Gamestudio Links
Zorro Links
Newest Posts
Executing Trades on Next Bar Open
by vicknick. 06/13/24 08:51
Zorro Beta 2.61: PyTorch
by jcl. 06/10/24 14:42
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (Akow, AndrewAMD), 666 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19059 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 3 1 2 3
How To Attach Walking Entity to Path? #347496
11/15/10 17:40
11/15/10 17:40
Joined: Oct 2010
Posts: 346
USA
RealSerious3D Offline OP
Senior Member
RealSerious3D  Offline OP
Senior Member

Joined: Oct 2010
Posts: 346
USA
Hello All,

I have learned how to code a NPC entity to move of its own accord and play the entity's walk animation. I have created a path in the level using WED's Add Path. I have also attached the path to the entity by adding it via clicking the folder entitled Path under Properties. However, the entity walks straight forward and does not follow the path. I am assuming I need to do something code-wise to get this to work? So, what do I do to make an entity move along a path?

Thanks in advance!

Re: How To Attach Walking Entity to Path? [Re: RealSerious3D] #347498
11/15/10 17:45
11/15/10 17:45
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
There's an example in the manual, see "path_scan":

Code:
action patrol_path()
 {
 // attach entity to nearest path
  result = path_scan(me,my.x,my.pan,vector(360,180,1000));
  if (result == 0) { return; } // no path found
 
 // find first waypoint
  var node = 1; // start at first node
  path_nodepos(my,node,my.skill20);
 
  while (1)
  {
    var angle[3];
 // find direction
    result = vec_to_angle(angle,vec_diff(temp,my.skill20,my.x));
 
 // near target? Find next waypoint of the path
    if (result < 25) {
      node = path_nextnode(my,node,1);
      path_nodepos(my,node,my._TARGET_X);
    }
 
 // turn and walk towards target
    my.pan = angle[0];
    c_move(me,vector(3*time_step,0,0),NULL,GLIDE); // walk ahead...
    wait(1);
  }
}




"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: How To Attach Walking Entity to Path? [Re: Superku] #347499
11/15/10 17:53
11/15/10 17:53
Joined: Oct 2010
Posts: 346
USA
RealSerious3D Offline OP
Senior Member
RealSerious3D  Offline OP
Senior Member

Joined: Oct 2010
Posts: 346
USA
Thank you for all your help today!

I get an error with the following:

path_nodepos

The error is:

Call function path_nodepos error
< path_nodepos(my,node,my.skll20);>

I am not a programmer, but an artist. So please forgive me if I am missing something very obvious.

Thanks!

Re: How To Attach Walking Entity to Path? [Re: RealSerious3D] #347500
11/15/10 18:05
11/15/10 18:05
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
You're welcome (back).

Yes, the example in the manual is outdated. I've wrote a new one, give it a try:

Code:
// attach path in WED !
action follow_path() {
	my.skill1 = 1; //start with first node
	path_getnode(my,my.skill1,my.skill2,NULL);
	while(1) {
		
		// close to node => get position of next node
		my.skill4 = my.z;
		if(vec_dist(my.skill2,my.x) < 16) {
			my.skill1 = path_nextnode(my, my.skill1, 1);
			path_getnode(my,my.skill1,my.skill2,NULL);
		}
		
		// turn to next node
		vec_diff(my.skill5,my.skill2,my.x);
		vec_to_angle(my.pan,my.skill5);
		my.tilt = 0;
		
		c_move(me,vector(5*time_step,0,0),nullvector,GLIDE | IGNORE_PASSABLE);
		wait(1);
	}
}




"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: How To Attach Walking Entity to Path? [Re: Superku] #347501
11/15/10 18:09
11/15/10 18:09
Joined: Oct 2010
Posts: 346
USA
RealSerious3D Offline OP
Senior Member
RealSerious3D  Offline OP
Senior Member

Joined: Oct 2010
Posts: 346
USA
OK! Now he glides along the path! Thank you very, very much. Now I need to alter this code so that the players "walk" animation plays and to slow down the forward movement a little (it's a casual stroll laugh ).

Thanks again!

Re: How To Attach Walking Entity to Path? [Re: RealSerious3D] #347502
11/15/10 18:16
11/15/10 18:16
Joined: Oct 2010
Posts: 346
USA
RealSerious3D Offline OP
Senior Member
RealSerious3D  Offline OP
Senior Member

Joined: Oct 2010
Posts: 346
USA
OK! I got that working. Here's the current code:

Code:
action walking_npc()
{
	my.skill1 = 1; //start with first node
	path_getnode(my,my.skill1,my.skill2,NULL);
	while(1) {
		
		// close to node => get position of next node
		my.skill4 = my.z;
		if(vec_dist(my.skill2,my.x) < 16) {
			my.skill1 = path_nextnode(my, my.skill1, 1);
			path_getnode(my,my.skill1,my.skill2,NULL);
		}
		
		// turn to next node
		vec_diff(my.skill5,my.skill2,my.x);
		vec_to_angle(my.pan,my.skill5);
		my.tilt = 0;
		
		c_move(me,vector(2*time_step,0,0),nullvector,GLIDE | IGNORE_PASSABLE);
		ent_animate(me, "walk", walk_percentage, ANM_CYCLE); 
		walk_percentage += 4 * time_step; 
		wait(1);
	}
}



Now, how does one use the path_spline command (or something similar) to allow for smooth transitions from node to node (i.e. rounding corners)?

Re: How To Attach Walking Entity to Path? [Re: RealSerious3D] #347506
11/15/10 18:29
11/15/10 18:29
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
The first action uses the path_spline command, the second code is similar to the old code, but rotates smoothly.
You can adjust the rotation speed here:
clamp(ang(my.skill8-my.pan)*0.25,-5,5)*time_step;
5 (and -5) is the maximal angular speed, the factor 0.25 makes the rotation smoother and slower.

Code:
// attach path in WED !
action follow_path_spline() {
	while(1) {
		
		vec_set(my.skill2,my.x);
		
		path_spline(me,my.x,my.skill1);
		my.skill1 += 3*time_step;


		vec_diff(my.skill5,my.x,my.skill2);
		vec_to_angle(my.skill8,my.skill5);
		
		my.pan += clamp(ang(my.skill8-my.pan)*0.25,-5,5)*time_step;
		
		wait(1);
	}
}

action follow_path_smooth() {
	my.skill1 = 1; //start with first node
	path_getnode(my,my.skill1,my.skill2,NULL);
	while(1) {
		
		// close to node => get position of next node
		my.skill4 = my.z;
		if(vec_dist(my.skill2,my.x) < 16) {
			my.skill1 = path_nextnode(my, my.skill1, 1);
			path_getnode(my,my.skill1,my.skill2,NULL);
		}
		
		// turn to next node
		vec_diff(my.skill5,my.skill2,my.x);
		vec_to_angle(my.skill8,my.skill5);
		
		my.pan += clamp(ang(my.skill8-my.pan)*0.25,-5,5)*time_step;
		
		c_move(me,vector(5*time_step,0,0),nullvector,GLIDE | IGNORE_PASSABLE);
		wait(1);
	}
}




"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: How To Attach Walking Entity to Path? [Re: Superku] #347517
11/15/10 20:33
11/15/10 20:33
Joined: Oct 2010
Posts: 346
USA
RealSerious3D Offline OP
Senior Member
RealSerious3D  Offline OP
Senior Member

Joined: Oct 2010
Posts: 346
USA
You are THE MAN! Thank you very much! This helps a ton! And I am learning a little coding in the process.

Re: How To Attach Walking Entity to Path? [Re: RealSerious3D] #347532
11/16/10 00:04
11/16/10 00:04
Joined: Oct 2010
Posts: 346
USA
RealSerious3D Offline OP
Senior Member
RealSerious3D  Offline OP
Senior Member

Joined: Oct 2010
Posts: 346
USA
OK! So far this is working great! I just need one thing more if someone can help. The NPC is walking smoothly along the path. Fantastic! But he does not step down if the ground suddenly lowers (like at a curb's edge). Instead, he keeps walking as if floating 6" in the air. He will step UP to get over something, but then, once to the other side, stay at that height and continue to float right along. What do I need to add to my code to make the NPC step down and up when the level geometry varies?

Here is my code so far (thanks to Superku!):

Code:
action follow_path_smooth() {
	my.skill1 = 1; //start with first node
	path_getnode(my,my.skill1,my.skill2,NULL);
	while(1) {
		
		// close to node => get position of next node
		my.skill4 = my.z;
		if(vec_dist(my.skill2,my.x) < 16) {
			my.skill1 = path_nextnode(my, my.skill1, 1);
			path_getnode(my,my.skill1,my.skill2,NULL);
		}
		
		// turn to next node
		vec_diff(my.skill5,my.skill2,my.x);
		vec_to_angle(my.skill8,my.skill5);
		
		my.pan += clamp(ang(my.skill8-my.pan)*0.25,-5,5)*time_step;
		
		c_move(me,vector(2*time_step,0,0),nullvector,GLIDE | IGNORE_PASSABLE);
		ent_animate(me, "walk", walk_percentage, ANM_CYCLE); 
		walk_percentage += 4 * time_step;
		
		wait(1);
	}
}



Thanks again for all the help!

Re: How To Attach Walking Entity to Path? [Re: RealSerious3D] #347534
11/16/10 00:14
11/16/10 00:14
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Code:
action follow_path_smooth() {
	my.skill1 = 1; //start with first node
	path_getnode(my,my.skill1,my.skill2,NULL);
	wait(1);
	c_setminmax(my);
	vec_scale(my.min_x,0.8);
	vec_scale(my.max_x,0.8);
	while(1) {
		
		// close to node => get position of next node
		my.skill4 = my.z;
		if(vec_dist(my.skill2,my.x) < 16) {
			my.skill1 = path_nextnode(my, my.skill1, 1);
			path_getnode(my,my.skill1,my.skill2,NULL);
		}
		
		// turn to next node
		vec_diff(my.skill5,my.skill2,my.x);
		vec_to_angle(my.skill8,my.skill5);
		
		my.pan += clamp(ang(my.skill8-my.pan)*0.25,-5,5)*time_step;
		
		c_trace(my.x,vector(my.x,my.y,my.z-500),IGNORE_ME | USE_BOX);
		my.z += (target.z+??-my.min_z*1.25-my.z)*0.25*time_step;
				
		c_move(me,vector(2*time_step,0,0),nullvector,GLIDE | IGNORE_PASSABLE);
		
		ent_animate(me, "walk", my.skill11, ANM_CYCLE);
		my.skill11 += 4 * time_step;
		my.skill11 %= 100;
		wait(1);
	}
}



Should work. Remove the "+??". If the NPC is floating in the air or if his feet are stuck in the ground, add "+??" again and replace the ?? with some values (trial and error... positive values to lift him).


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Page 1 of 3 1 2 3

Gamestudio download | chip programmers | 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