[ANet] enemy

Posted By: larafale

[ANet] enemy - 09/29/12 18:08

Hi,

How can i get the distance between the player and an enemy?

Thanks
Posted By: Ch40zzC0d3r

Re: [ANet] enemy - 09/29/12 18:17

You need position from both. Then you can do vec_dist(...) or vec_lenth(...) - vec_length(...)
Posted By: MasterQ32

Re: [ANet] enemy - 09/29/12 20:58

this won't work!
Code:
vec_lenth(...) - vec_length(...)


you can't calculate the difference between two vectors to the orginin in order to calculate the distance from those two vectors
it's like calculating the difference from city a to city b when comparing the difference from city a to city c and city b to city c

just use vec_dist to calculate the distance between to vectors
Posted By: larafale

Re: [ANet] enemy - 09/30/12 08:23

Thanks. I try that.
Posted By: larafale

Re: [ANet] enemy - 09/30/12 10:14

I wrote that in my enemy function as a test

var dist_player_enemy;
you=players[enet_ent_creator(enet_ent_globpointer(me))];
vec_set(player_pos.x,you.x);
vec_set(temporary.x, my.x);
dist_player_enemy=vec_dist (player_pos.x, temporary.x);
if (dist_player_enemy <= 1000) snd_play(alarm_wav, 100, 0);

I have no error, but it dosen't work!
Can you tell me what is wrong?
Posted By: MasterQ32

Re: [ANet] enemy - 09/30/12 10:19

you are comparing the distance between me and me which is always 0

you should check out this line:
you=players[enet_ent_creator(enet_ent_globpointer(me))];
i think that you want to get the distance to your player in the enemies function
so you need to pass the player to enet_ent_globpointer, not me
Posted By: larafale

Re: [ANet] enemy - 09/30/12 13:18

Is that correct?

cl_id = enet_get_clientid();
you=players[enet_ent_creator(enet_ent_globpointer(players[cl_id]))];
Posted By: MasterQ32

Re: [ANet] enemy - 09/30/12 13:54

yes, this should work
also you can calc the distance between you and me directly:
vec_dist(you.x, my.x)
Posted By: larafale

Re: [ANet] enemy - 09/30/12 14:36

Here is the enemy function as a test
function enemy()
{
cl_id = enet_get_clientid();
you=players[enet_ent_creator(enet_ent_globpointer(players[cl_id]))];
//................................................................
my.emask = ENABLE_SHOOT; // the enemy is sensitive to impact with player's bullets
my.event = enemy_got_shot; // and runs this function when it is hit
if (vec_dist (you.x, my.x) < 1000) snd_play(alarm_wav, 100, 0);
wait (1);
}
I can shoot at the enemy, but it can't see me. What i can do?
Posted By: MasterQ32

Re: [ANet] enemy - 09/30/12 15:16

you should create a loop for the checking
is it is now, it will be executed only once
Posted By: Dark_samurai

Re: [ANet] enemy - 09/30/12 15:32

Code:
you=players[enet_ent_creator(enet_ent_globpointer(players[cl_id]))];



I assume that players[] is an array where the local pointer of each player is stored. The index is the client id of the player.

If my assumption is correct, it should be like this (code snippet running in the enemies function):

Code:
// get the pointer to the player
you = players[enet_get_clientid()];
// calc distance between enemy and player
distance = vec_dist(you.x, my.x);

Posted By: larafale

Re: [ANet] enemy - 09/30/12 17:36

Thanks a lot, it works fine into the real enemy function.
© 2024 lite-C Forums