|
HOW: Multiple Entities on ONE path
#134869
06/09/07 05:19
06/09/07 05:19
|
Joined: Sep 2006
Posts: 106 FairyLand!!!
RruthH
OP
Member
|
OP
Member
Joined: Sep 2006
Posts: 106
FairyLand!!!
|
Hey ppl, I waz wonderin' how to code multiple entities and assign them to one path. I already have my action code. Made it w/ the help of Kinji's Pathfinding tutorial. (great tut btw ). But when assigning it to more than one entity, only one follows the path and the other one doesn't move/do anything. Here's my code: Code:
action truck { wait(1); move_truck(); ////////// 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; }
///////////////get 1st node on path path_getnode(my,1,pos_node,null); vec_to_angle(my.pan,vec_diff(temp,pos_node,my.x)); while(1) { wait(1); distance = vec_dist(my.x,pos_node); if(distance < 25) { switch = off; node = path_nextnode(my,node,1); path_getnode(my,node,pos_node, null); vec_to_angle(my.pan,vec_diff(temp,pos_node,my.x)); wait(1); switch = 1; // start moving again } } }
/////////////////////////////////
function move_truck() { while(1) { wait(1); if(switch == 1) { c_move(truck_ent,truck_speed,nullvector,IGNORE_YOU|GLIDE); } ent_animate(my,"frame",path_anim_speed,anm_cycle); path_anim_speed += 3 * time; path_anim_speed %= 100; } }
Any idea how to make multiple entities follow a single path using this action? Thanks!
|
|
|
Re: HOW: Multiple Entities on ONE path
[Re: RruthH]
#134870
06/09/07 15:30
06/09/07 15:30
|
Joined: Sep 2003
Posts: 281 Arkansas\USA
raiden
Member
|
Member
Joined: Sep 2003
Posts: 281
Arkansas\USA
|
You need to use skills for all the variables in your code. This way each object uses it's own copy of the variable.
If you need an example let me know.
-raiden
"It doesn't matter if we win or lose, it's how we make the game."-------------------- Links: 3DGS for Dummies
|
|
|
Re: HOW: Multiple Entities on ONE path
[Re: RruthH]
#134873
06/11/07 12:01
06/11/07 12:01
|
Joined: Sep 2006
Posts: 106 FairyLand!!!
RruthH
OP
Member
|
OP
Member
Joined: Sep 2006
Posts: 106
FairyLand!!!
|
Oh no... Mine doesn't seem to work, Even tho i've used DEFINE. Still trying to fix it. @raiden If you have time, I'd like to see that example code please... Thanks very much!!!
|
|
|
Re: HOW: Multiple Entities on ONE path
[Re: RruthH]
#134874
06/11/07 15:46
06/11/07 15:46
|
Joined: Sep 2006
Posts: 106 FairyLand!!!
RruthH
OP
Member
|
OP
Member
Joined: Sep 2006
Posts: 106
FairyLand!!!
|
But I think I did it right. Here's my code. Code:
action car { my.scale_x = 0.292; my.scale_y = 0.292; my.scale_z = 0.292; var node = 1; var node_pos[3]; var distance; ///////////////////////////////////// // my.node = 1; my.passable = on; result = path_scan(my,my.x,my.pan,vector(360,180,1000)); if(result == 0){return;}
fade_in(); move_car(); /////////////////////////////////// path_getnode(my,1,node_pos,null); vec_to_angle(my.pan,vec_diff(temp,node_pos,my.x)); while(1) { wait(1); distance = vec_dist(my.x,node_pos); if(distance < 25) { node = path_nextnode(my,node,1); path_getnode(my,node,node_pos,null); vec_to_angle(my.pan,vec_diff(temp,node_pos,my.x)); wait(1); } if(node >= 11) { fade_out(); return; } wait(1); } } Then I use this action to make countless numbers of cars every 10 seconds: Code:
action car_creator { my.passable = on; my.invisible = on; while(1) { ent_create("car1.mdl",my.x,car); sleep(5); } } However, not one of the generated cars follow the path. The cars just move straight. Not following paths or anything. Have I missed something? I really need to fix this. Thanks!
|
|
|
Re: HOW: Multiple Entities on ONE path
[Re: RruthH]
#134875
06/11/07 16:40
06/11/07 16:40
|
Joined: Jul 2002
Posts: 3,208 Germany
Error014
Expert
|
Expert
Joined: Jul 2002
Posts: 3,208
Germany
|
Quote:
But I think I did it right.
OBJECTION!
OHNO STRIKE BACK!
Judge agrees!
Okay, thats enough.
Let's have a look at your function that moves the entities. It's called "move_car".
Whoa!
(Okay, I'm really done now)
Specifically, this part:
Code:
if(switch == 1) { c_move(truck_ent,truck_speed,nullvector,IGNORE_YOU|GLIDE); }
Here, we have some things that I don`t like. And all in this short piece of code!
At first, it only moves as long as "switch" is equal to one. You likely have a variable called "switch" SOMEWHERE in your code - if its not set to 1, it won't work at all. Maybe you should make this a flag? Like this.
Code:
if(my.flag1 == on) { ... REST GOES HERE
This has some advantages: For example, you can now stop the cars individually and not just all at once. You can also combine that with your general swtich-variable, then you can stop them all at once (set switch to something other than 1) or just stop them by switching their flag1 to off.
Note though that you have to put the line "my.flag1 = on;" into the action of your trucks now.
Okay, I guess I won't be done for quite a while
So then. What else don't I like?
If you look at the c_move-instruction, you can clearly see that it only moves "truck_ent". That is a pointer. Pointer a magical beings full of HATE AND PAIN. Actually, they're quite neat. They point to things: In this case, they point to whatever entity we want to move. Who is it, then?
OH NO!
See? There is no line like "truck_ent=me;" anywhere in your code. Well, maybe it is in your fade_in-function, but I doubt that. So there.
Due to the fact that you call this from the entities' action, it would make sense to move the entity that originally called that function. We can simply use "me" here. No, not me, the pointer, of course!
Code:
c_move(me,truck_speed,nullvector,IGNORE_YOU|GLIDE);
The last thing that I don't like is "truck_speed". We expect a vector here, which states how to move that entity (you know... forward? Upwards?). You have to define it somewhere! Again, you could make this a skill of an entity or you could be superlazy and do this
Code:
c_move(truck_ent,vector(25*time_step,0,0),nullvector,IGNORE_YOU|GLIDE);
It's much, much, much better this way, because now there is a "time_Step" in there. This guarantees the same behaviour on different machines - otherwise, your truck would move faster on faster computers!
Thats all that I saw, but I haven't looked that long at your code, so maybe I missed something. Tell me if it works!
It is also true that I mainly did this post because I finally could use that Objection-site.
Also:
Quote:
...numbers of cars every 10 seconds:
Quote:
sleep(5);
OBJECTION!
Last edited by Error014; 06/11/07 16:42.
Perhaps this post will get me points for originality at least.
Check out Dungeon Deities! It's amazing and will make you happy, successful and almost certainly more attractive! It might be true!
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|