SA-MP Forums Archive
[HELP] Detecting the angle from checkpoints - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: [HELP] Detecting the angle from checkpoints (/showthread.php?tid=171657)



[HELP] Detecting the angle from checkpoints - RoCK'N'Rolla - 27.08.2010

guyz, i have a racing script, but i need to detect angle from first two checkpoints. I can do it with "atan", bur dunno how to do. Can some1 help me?


Re: [HELP] Detecting the angle from checkpoints - Mauzen - 27.08.2010

The best way would be using atan2, because you do not have to calc a lot for this. It requires the x and y difference between your two points.
All in all you could get the angle like this:

atan2(x1 - x2, y1 - y2)

with x1/y1 being your first checkpoint, and x2/y2 the other


Re: [HELP] Detecting the angle from checkpoints - RoCK'N'Rolla - 27.08.2010

atan2(x1 - x2, y1 - y2)

there must be a "/" between x2 and y1, but you wrote ",". Is it true?

and how will i use it? i mean:

new Float:angle;

angle = atan2(x1 - x2, y1 - y2) ?


Re: [HELP] Detecting the angle from checkpoints - RoCK'N'Rolla - 27.08.2010

mauzen? will you answer?


Re: [HELP] Detecting the angle from checkpoints - Mauzen - 27.08.2010

Yep, the , is correct. There are two types of atan, the normal one (this would require a / ) and atan2 (easier to use)

The result will be the angle in degrees. Maybe it can be a negative value, not sure about this atm, if it is, you can add 180 to the result to make it more useful.


Re: [HELP] Detecting the angle from checkpoints - RoCK'N'Rolla - 28.08.2010

I tried it but it still didnt work. I want to make a spawn angle for the first checkpoint, here is the codes:

pawn Код:
new Float:angle;

angle = atan2(RaceCheckpoints[CurrentCheckpoint[playerid]][0] - RaceCheckpoints[CurrentCheckpoint[playerid]+1][0] , RaceCheckpoints[CurrentCheckpoint[playerid]][1] - RaceCheckpoints[CurrentCheckpoint[playerid]+1][1])
SetPlayerFacingAngle(playerid, angle);
SetPlayerPos(playerid,RaceCheckpoints[CurrentCheckpoint[playerid]][0],RaceCheckpoints[CurrentCheckpoint[playerid]][1],RaceCheckpoints[CurrentCheckpoint[playerid]][2]);



Re: [HELP] Detecting the angle from checkpoints - RoCK'N'Rolla - 28.08.2010

Any help?


Re: [HELP] Detecting the angle from checkpoints - RyDeR` - 28.08.2010

You used a comma. Use '/' to divide them with each other.


Re: [HELP] Detecting the angle from checkpoints - RoCK'N'Rolla - 29.08.2010

But that is "atan2", not "atan". Sorry if im wrong, but isn't it true?