SA-MP Forums Archive
Get distance between 2 points. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Get distance between 2 points. (/showthread.php?tid=228614)



Get distance between 2 points. - -=SR=- - 20.02.2011

I been trying to figure this out, and cannot think of a way to do this.
I need to get a distance between 2 points. Anybody have any idea or some suggestions on how to do this?

Thanks, SR


Re: Get distance between 2 points. - bigcomfycouch - 20.02.2011

pawn Код:
stock GetDistance( Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2 )
{
    return floatround( floatsqroot( ( ( x1 - x2 ) * ( x1 - x2 ) ) + ( ( y1 - y2 ) * ( y1 - y2 ) ) + ( ( z1 - z2 ) * ( z1 - z2 ) ) ) ) );
}



Re: Get distance between 2 points. - -=SR=- - 20.02.2011

thanks, gona give it a try, will post back here with results


Re: Get distance between 2 points. - -=SR=- - 23.02.2011

It works for what I needed, thanks a lot.


Re: Get distance between 2 points. - Stefan_Toretto - 07.03.2011

This is in meters? or Kilometers?


Re: Get distance between 2 points. - [DRD]Rodney - 04.09.2011

I failed. wrong post.


Re: Get distance between 2 points. - rt-2 - 02.03.2016

Quote:
Originally Posted by bigcomfycouch
Посмотреть сообщение
pawn Код:
stock GetDistance( Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2 )
{
    return floatround( floatsqroot( ( ( x1 - x2 ) * ( x1 - x2 ) ) + ( ( y1 - y2 ) * ( y1 - y2 ) ) + ( ( z1 - z2 ) * ( z1 - z2 ) ) ) ) );
}
Quote:
Originally Posted by -=SR=-
Посмотреть сообщение
It works for what I needed, thanks a lot.
The code is actually:
Код:
pawn Код:
stock GetDistance( Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2 ){    return floatround( floatsqroot( ( ( x1 - x2 ) * ( x1 - x2 ) ) + ( ( y1 - y2 ) * ( y1 - y2 ) ) + ( ( z1 - z2 ) * ( z1 - z2 ) ) )  );}
You had one too many ')'


Re: Get distance between 2 points. - Sascha - 02.03.2016

Quote:
Originally Posted by blinkpnk
Посмотреть сообщение
The code is actually:
Код:
pawn Код:
stock GetDistance( Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2 ){    return floatround( floatsqroot( ( ( x1 - x2 ) * ( x1 - x2 ) ) + ( ( y1 - y2 ) * ( y1 - y2 ) ) + ( ( z1 - z2 ) * ( z1 - z2 ) ) )  );}
You had one too many ')'
Not really, with 3 ) at the end you just close the "floatsqroot" function
the 4th ) closes the "floatround"


Re: Get distance between 2 points. - rt-2 - 05.03.2016

IDK but I had to remove one in my code because of error.
But again, PAWNO is a very mysterious world.


Re: Get distance between 2 points. - AbyssMorgan - 05.03.2016

distance in integer, wtf
PHP код:
stock Float:GetDistanceBetweenPoints3D(Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2){
    return 
VectorSize(x1-x2,y1-y2,z1-z2);