Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (Ayumi), 662 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
[ANet] enemy #408337
09/29/12 18:08
09/29/12 18:08
Joined: Sep 2012
Posts: 21
France
larafale Offline OP
Newbie
larafale  Offline OP
Newbie

Joined: Sep 2012
Posts: 21
France
Hi,

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

Thanks

Re: [ANet] enemy [Re: larafale] #408338
09/29/12 18:17
09/29/12 18:17
Joined: Oct 2011
Posts: 1,082
Germany
C
Ch40zzC0d3r Offline
Serious User
Ch40zzC0d3r  Offline
Serious User
C

Joined: Oct 2011
Posts: 1,082
Germany
You need position from both. Then you can do vec_dist(...) or vec_lenth(...) - vec_length(...)

Re: [ANet] enemy [Re: Ch40zzC0d3r] #408345
09/29/12 20:58
09/29/12 20:58
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
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


Visit my site: www.masterq32.de
Re: [ANet] enemy [Re: MasterQ32] #408360
09/30/12 08:23
09/30/12 08:23
Joined: Sep 2012
Posts: 21
France
larafale Offline OP
Newbie
larafale  Offline OP
Newbie

Joined: Sep 2012
Posts: 21
France
Thanks. I try that.

Re: [ANet] enemy [Re: larafale] #408364
09/30/12 10:14
09/30/12 10:14
Joined: Sep 2012
Posts: 21
France
larafale Offline OP
Newbie
larafale  Offline OP
Newbie

Joined: Sep 2012
Posts: 21
France
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?

Re: [ANet] enemy [Re: larafale] #408365
09/30/12 10:19
09/30/12 10:19
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
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


Visit my site: www.masterq32.de
Re: [ANet] enemy [Re: MasterQ32] #408372
09/30/12 13:18
09/30/12 13:18
Joined: Sep 2012
Posts: 21
France
larafale Offline OP
Newbie
larafale  Offline OP
Newbie

Joined: Sep 2012
Posts: 21
France
Is that correct?

cl_id = enet_get_clientid();
you=players[enet_ent_creator(enet_ent_globpointer(players[cl_id]))];

Re: [ANet] enemy [Re: larafale] #408379
09/30/12 13:54
09/30/12 13:54
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
yes, this should work
also you can calc the distance between you and me directly:
vec_dist(you.x, my.x)


Visit my site: www.masterq32.de
Re: [ANet] enemy [Re: MasterQ32] #408383
09/30/12 14:36
09/30/12 14:36
Joined: Sep 2012
Posts: 21
France
larafale Offline OP
Newbie
larafale  Offline OP
Newbie

Joined: Sep 2012
Posts: 21
France
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?

Re: [ANet] enemy [Re: larafale] #408390
09/30/12 15:16
09/30/12 15:16
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
you should create a loop for the checking
is it is now, it will be executed only once


Visit my site: www.masterq32.de
Page 1 of 2 1 2

Moderated by  HeelX, Spirit 

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