|
Following one entity with another
#260943
04/14/09 20:29
04/14/09 20:29
|
Joined: Mar 2009
Posts: 23
Siegewolf
OP
Newbie
|
OP
Newbie
Joined: Mar 2009
Posts: 23
|
I have a bit of a general problem (I am still new to lite C). Suppose I have code as below; In follower_action, how to make the follower's coordinates always be the same as that of the entity which was passed to add_follower?
action follower_action()
{
while(1)
{
me.x = ?;
me.y = ?;
me.z = ?;
wait(1);
}
}
function add_follower(ENTITY* ent)
{
ENTITY* follower = ent_create(... ,follower_action);
}
Last edited by Siegewolf; 04/14/09 20:30.
|
|
|
Re: Following one entity with another
[Re: Siegewolf]
#260946
04/14/09 20:56
04/14/09 20:56
|
Joined: Feb 2006
Posts: 385 Oldenburg,Germany
Ralph
Senior Member
|
Senior Member
Joined: Feb 2006
Posts: 385
Oldenburg,Germany
|
Try this:
action follower_action()
{
ENTITY* ent = ptr_for_handle(my.skill10);
while(1)
{
vec_set(my.x,ent.x);
wait(1);
}
}
function add_follower(ENTITY* ent)
{
ENTITY* follower = ent_create(... ,follower_action);
if(ent != NULL)follower.skill10 = handle(ent);
}
EDIT: I never heard about that...
Last edited by Ralph; 04/14/09 21:07.
|
|
|
Re: Following one entity with another
[Re: Ralph]
#261111
04/15/09 21:34
04/15/09 21:34
|
Joined: Mar 2009
Posts: 23
Siegewolf
OP
Newbie
|
OP
Newbie
Joined: Mar 2009
Posts: 23
|
The code exactly as you wrote it does not work for me (it is not following), but if I put ENTITY* ent = ptr_for_handle(my.skill10); within the loop, as below, it does work. I have no clue why is this happening. Any explanation?
action follower_action()
{
while(1)
{
ENTITY* ent = ptr_for_handle(my.skill10);
vec_set(my.x,ent.x);
wait(1);
}
}
|
|
|
Re: Following one entity with another
[Re: Siegewolf]
#261124
04/15/09 22:31
04/15/09 22:31
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Could be because follower action is starting "too" quickly, before my is finished being created. Try this. action follower_action()
{
wait(1);
ENTITY* ent = ptr_for_handle(my.skill10);
while(1)
{
vec_set(my.x,ent.x);
wait(1);
}
}
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Following one entity with another
[Re: EvilSOB]
#261302
04/16/09 20:24
04/16/09 20:24
|
Joined: Mar 2009
Posts: 23
Siegewolf
OP
Newbie
|
OP
Newbie
Joined: Mar 2009
Posts: 23
|
Could be because follower action is starting "too" quickly, before my is finished being created. Try this. Thanks EvilSOB, that works. Now I must know when entity is destroyed to stop setting position of follower. I wrote something like this:
action follower_action()
{
wait(1);
while(1)
{
ENTITY* ent = ptr_for_handle(my.skill10);
if (ent != NULL)
vec_set(my.x,ent.x);
wait(1);
}
}
If new entity appears in the meantime after current one is destroyed, follower jumps on that new entity as if handle has been reassigned to new entity. How can I positively detect that the original entity has been destroyed?
|
|
|
Re: Following one entity with another
[Re: Siegewolf]
#261365
04/17/09 07:30
04/17/09 07:30
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Easy, use this, it what I understand you to be after.
action follower_action()
{
wait(1);
ENTITY* ent = ptr_for_handle(my.skill10);
while(ent)
{
vec_set(my.x,ent.x);
wait(1);
if(ent != ptr_for_handle(my.skill10)) ent = NULL;
}
}
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Following one entity with another
[Re: EvilSOB]
#261583
04/18/09 18:04
04/18/09 18:04
|
Joined: Mar 2009
Posts: 23
Siegewolf
OP
Newbie
|
OP
Newbie
Joined: Mar 2009
Posts: 23
|
Easy, use this, it what I understand you to be after. Yup, this is it! Thanks a lot EvilSOB. *** Thanks everyone for the help so far!
|
|
|
|