2 registered members (Akow, AndrewAMD),
666
guests, and 2
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
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
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
There's an example in the manual, see "path_scan":
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: RealSerious3D]
#347500
11/15/10 18:05
11/15/10 18:05
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
Senior Expert
|
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:
// 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
OP
Senior Member
|
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 ). 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
OP
Senior Member
|
OP
Senior Member
Joined: Oct 2010
Posts: 346
USA
|
OK! I got that working. Here's the current 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
Senior Expert
|
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.
// 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: RealSerious3D]
#347532
11/16/10 00:04
11/16/10 00:04
|
Joined: Oct 2010
Posts: 346 USA
RealSerious3D
OP
Senior Member
|
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!):
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
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
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
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|