Gamestudio Links
Zorro Links
Newest Posts
nba2king Latest Roster Update Breakdown
by joenxxx. 10/14/25 06:06
Help!
by VoroneTZ. 10/14/25 05:04
Zorro 2.70
by jcl. 10/13/25 09:01
ZorroGPT
by TipmyPip. 10/12/25 13:58
Sam Foster Sound | Experienced Game Composer for Hire
by titanicpiano14. 10/11/25 18:45
Reality Check results on my strategy
by dBc. 10/11/25 06:15
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
2 registered members (Grant, joenxxx), 9,921 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
joenxxx, Jota, krishna, DrissB, James168
19170 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Paths are making me crazy!!! #121677
04/05/07 19:22
04/05/07 19:22
Joined: Mar 2005
Posts: 969
ch
Loopix Offline OP
User
Loopix  Offline OP
User

Joined: Mar 2005
Posts: 969
ch
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.

Re: Paths are making me crazy!!! [Re: Loopix] #121678
04/05/07 22:26
04/05/07 22:26
Joined: May 2005
Posts: 2,713
Lübeck
Slin Offline
Expert
Slin  Offline
Expert

Joined: May 2005
Posts: 2,713
Lübeck
I never worked with paths, but I think the problem is, that node is null after the last node was reached. There is no node with the number 0, wich could be a problem for path_nextnode();.

I would suggest, to add a simple if statement:

if(distance < 25)
{
node = path_nextnode(my,node,1);
if(!node){node = 1;} //if the last node was reached, start again with the first one
path_getnode(my,node,pos_node, null);
vec_to_angle(temp_pan,vec_diff(temp,pos_node,my.x));
wait(1);
}


I hope this helps,
Slin

Re: Paths are making me crazy!!! [Re: Slin] #121679
04/05/07 22:39
04/05/07 22:39
Joined: Mar 2005
Posts: 969
ch
Loopix Offline OP
User
Loopix  Offline OP
User

Joined: Mar 2005
Posts: 969
ch
yeah, it was as simple as that... Thanks for helping a noob like me!


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1