Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
3 registered members (AndrewAMD, The_Judge, Grant), 898 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
compare distances to the player #116713
03/12/07 03:58
03/12/07 03:58
Joined: Mar 2007
Posts: 31
G
gamehack3r Offline OP
Newbie
gamehack3r  Offline OP
Newbie
G

Joined: Mar 2007
Posts: 31
i was wonder how do i compare the distances of entities to the player. For example im using a trigger event_scan on the actors, the actors then send their coords to the "player". I need to be able to sort out which of the 5 actors is the closest in order.

function ACTOR
{
if(event_type == event_scan)
checkposition(); //check to see if any other coords have been sent
}

function checkposition
{
coordslot += 1; //ads 1 counter to the coord slots (ALL slots are cleared every wait(1);)
if(coordslot == 1)&&(coordslot < maxslots) //places the coords in slot1 and checks to see if the slot is available
{
//copy the coords of the actor into the slot
coordslot1 = my.pos;
}
if(coordslot ==2 )
{
//copy the coords of the actor into the slot
coordslot2 = my.pos;
}
if(coordslot ==2 )
{
//copy the coords of the actor into the slot
coordslot2 = my.pos;
}

//compare distances of coords

return;
}

so at the moment i have the coords of 3 actors , how do i go about finding which is closest to furthest

Re: compare distances to the player [Re: gamehack3r] #116714
03/12/07 06:22
03/12/07 06:22
Joined: Aug 2005
Posts: 1,558
HK
V
vlau Offline
Serious User
vlau  Offline
Serious User
V

Joined: Aug 2005
Posts: 1,558
HK
vec_dist() is the best function to check distance
between entities.

Re: compare distances to the player [Re: vlau] #116715
03/12/07 10:16
03/12/07 10:16
Joined: Aug 2006
Posts: 128
Papua New Guinea
I
Impaler Offline
Member
Impaler  Offline
Member
I

Joined: Aug 2006
Posts: 128
Papua New Guinea
I don't know if this is faster, but sqrt((player.x - obj.x)^2 + (player.y - obj.y)^2 + (player.z - obj.z)^2) also works and it can be used for finding the horizontal distance only.


Murphey's Law:
<< if anything can go wrong, it will >>

(Murphey was an optimist).

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

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