Why does the duck not recatch the starting or nearest node after it's followed the path one time? I simply want to make it endlessly follow the path but I must be doing something wrong!
Code:
var temp_pan[3];
var pan_ang_smooth = 0.5;
var tilt_ang_smooth = 0.5;
var distance; // distance from entity to node
var node = 1; // node that we want to goto.. also shows what node we started with
var pos_node[3]; // array to hold node position
var switch = 0; // to set move on or off
entity* duck;
function move_duck()
{
// switch = 1;
while(1)
{
wait(1);
if(switch == 1){
c_move(duck,vector(10*time_step,0,0),nullvector,GLIDE);
ent_animate(my, "walk", my.skill1, anm_cycle);
my.skill1 += 10 * time_step; // 10//number controls the animation speed
//This part smoothes out the turn angles
vec_to_angle(temp_pan,vec_diff(temp,pos_node,my.x));
duck.pan += ang(temp_pan.pan -duck.pan)*pan_ang_smooth*time_step;
duck.tilt += ang(temp_pan.tilt -duck.tilt)*tilt_ang_smooth*time_step;
}
}
}
action duck_target
{
duck = me;
move_duck();
////////// attach entity to nearest path
result = path_scan(me,my.x,my.pan,vector(360,180,1000));
if (result == 0) { return; }
if(result) { switch =1; }
//////////// find first waypoint
path_getnode(my,1,pos_node, null); // set vec to node position
/////////// find direction and turn to it
vec_to_angle(my.pan,vec_diff(temp,pos_node,my.x)); // look at NODE
while(1)
{
wait(1);
distance = vec_dist(my.x, pos_node); // close to node?
if(distance < 25) // 25 is test number
{
node = path_nextnode(my,node,1);
path_getnode(my,node,pos_node, null);
vec_to_angle(temp_pan,vec_diff(temp,pos_node,my.x));
wait(1);
}
}
}
Any help appreciated.