View Single Post
03-09-16, 09:00 PM   #1
duzao7667
A Defias Bandit
Join Date: Mar 2016
Posts: 2
Calculate how much to turn with x,y and facing radians

Hello everyone o/

I'm trying to get the amount of degrees I need to turn to face object B (x=60,y=42 on map) but theres always mismatches, and I'm not talking about degree normalization (mod 360 or if degree>0 degree - 360) but the calc by itself. When i'm facin the oposite side of the object B i wont get an 180 degree (getting 170) and when facing the object (perfect line of sigh, completely pointed and on sight) I got 350 degrees on howMuchTurn oO
There's something wrong I failed to see or any lesson I forgot to learn?

The code snippet is the folowing:

Code:
SetMapToCurrentZone()
local actualX, actualY = GetPlayerMapPosition("player")
howMuchTurn=(radToDeg(GetPlayerFacing()) - radToDeg(math.atan2(actualX-60,actualY-42)))

...

function radToDeg(rad)
	return rad * (180 / math.pi)
end

--used this to normalize the coords
--howMuchTurn=math.fmod(howMuchTurn,360) --... but yet, unexpected 10 and -10 angles
PS: I used TomTom to verify the perfect 180 and 359/0 degrees to object B.
HALP! xD

Last edited by duzao7667 : 03-09-16 at 09:06 PM. Reason: fmod added
  Reply With Quote