This is an alternative way to create path finding/following by using vertex position
instead of traditional method.
Path creation
=============
- Firstly, fire up MED and click on "Create Vertex" button. (Step 1)
- On the top view window, move your mouse to desired position and left click
to create a vertex, this will be vertex #1 (or the first node). Repeat step 2
until all vertices (nodes) are created as you wish. (Step 2)
- Create a primitive (can be a cube, cone, or sphere) and place it in the world
centre. (Step 3) The primitive doesn't do anything to the path but if you ignore
it, you may encounter "Can't load" problem while you run the level.
- Check all vertices by clicking on "Vertex mode" and "Select" button. (Step 4)
drag and select each vertex and compare the vertex # shown on the lower right
bottom, make sure they are arranged in order. If you want to adjust the vertex
position, click on "Move" button, select and move the vertex to your desired
location. (Step 5)
- Finally name and save this model to your working directory. I call it vertexPath.mdl.
Create the level
================
- In WED, load the path model (vertexPath.mdl) and place it anywhere you want.
- Load your character/car/airplane model that will follow the path.
- Create a skybox, ground plane or any decorations if you want.
- Save and compile the level. (vertexPath.wmp)
Scripting
=========
Fire up SED and add the following codes :
Code:
//
// vertexPath.wdl
//
var video_mode = 8;
var video_depth = 32;
entity* vPath;
function main()
{
level_load("vertexPath.wmb");
wait(2);
}
action thePath
{
vPath = my;
my.passable = on;
my.invisible = on;
// Add some movement codes here....
}
define nodePos, skill1;
define nodeNo, skill4;
//uses: nodePos, nodeNo
action myCar
{
while(vPath==NULL) {wait(1);}
while(my)
{
//get next node
if (vec_dist(my.nodePos,my.x) < 35) // play with 35
{
my.nodeNo += 1;
my.nodeNo = cycle(my.nodeNo,1,9); // limited it 1 to 8
vec_for_vertex(my.nodePos,vPath,my.nodeNo);
}
//turn to new node position smoothly
vec_to_angle(temp,vec_diff(temp,my.nodePos,my.x));
my.pan += ang(temp.pan-my.pan)*0.05*time_step;
// In case you want to adjust tilt angle also
// my.tilt += ang(temp.tilt-my.tilt)*0.05*time_step;
c_move(my,vector(5*time_step,0,0),nullvector,glide); // play with 5
wait(1);
}
}
Add the script to your level in WED, assign the thePath and myCar action to the path
and the path following model respectively, compile then run. Thats it!
You may ask it won't save much workflow than the traditional pathfinding method,
I'll say yes, but I found this method very interesting and you can move the whole
path easily at runtime by adding some movement codes.
I want to share it with you because I found it quite useful, you can enchance it and
create some interesting things. For example, add a bug and let it moving around your
character's body....
You can download a demo level
here