[HELP] Detecting the angle from checkpoints
#1

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?
Reply
#2

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
Reply
#3

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) ?
Reply
#4

mauzen? will you answer?
Reply
#5

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.
Reply
#6

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]);
Reply
#7

Any help?
Reply
#8

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

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


Forum Jump:


Users browsing this thread: 2 Guest(s)