Calculating distance
#1

Hello, how can I calculate distance between two players? (in meters)

I'd appreciate if someone can make a function for me
Reply
#2

pawn Код:
stock GetDistanceBetweenPlayers(playerid,playerid2)
{
    new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
    new Float:tmpdis;
    GetPlayerPos(playerid,x1,y1,z1);
    GetPlayerPos(playerid2,x2,y2,z2);
    tmpdis = floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
    return floatround(tmpdis);
}
Credits: Unknow
Reply
#3

Better version:
pawn Код:
stock Float:GetDistanceBetweenPoints(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2)
{
        x1 -= x2;
    y1 -= y2;
    z1 -= z2;
    return floatsqroot((x1 * x1) + (y1 * y1) + (z1 * z1));
}
Reply
#4

Offtopic: Vince, LOL at your post in my sig.
Reply
#5

In most cases you only need (they are both native since 0.3a)

GetPlayerDistanceFromPoint or
GetVehicleDistanceFromPoint

in all other cases use Vince code
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)