Angle from Coordinates - 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: Angle from Coordinates (
/showthread.php?tid=451029)
Angle from Coordinates -
RedFusion - 15.07.2013
I've run into some problems with a racing script.
I want the player to be angled towards the next checkpoint, is this possible to get from the checkpoint coordinates?
If so, how?
pawn Код:
cp = player_cp[playerid];
if(cp == cps) nextcp = 0;
else nextcp = cp + 1;
x = race_cp[cp][0];
y = race_cp[cp][1];
z = race_cp[cp][2];
x2 = race_cp[nextcp][0];
y2 = race_cp[nextcp][1];
/*angle = ... ? */
Re: Angle from Coordinates -
PrinceKumar - 15.07.2013
You can do it if race is starting onfoot u can use
Re: Angle from Coordinates -
iggy1 - 15.07.2013
This returns a 2D angle between 2 points. From point A (first 2 args) to point b (3rd and 4th args).
pawn Код:
stock Float:PointToPoint(Float:X, Float:Y, Float:PointX, Float:PointY)
{
new Float:Angle;
if(X > PointX && Y > PointY)
Angle = floatabs(atan2(floatsub(PointX, X), floatsub(PointY, Y)));
if(X > PointX && Y <= PointY)
Angle = floatadd(floatabs(atan2(floatsub(Y, PointY), floatsub(PointX, X))), 270.0);
if(X <= PointX && Y > PointY)
Angle = floatadd(floatabs(atan2(floatsub(PointY, Y), floatsub(X, PointX))), 90.0);
if(X <= PointX && Y <= PointY)
Angle = floatadd(floatabs(atan2(floatsub(X, PointX), floatsub(Y, PointY))), 180.0);
return Angle >= 360.0 ? floatsub(Angle, 360.0) : Angle;
}
Define or forward that function before using it.
Re: Angle from Coordinates -
RedFusion - 15.07.2013
Thanks, iggy.