Getting angle of joypad controller using Atan2?

Advanced game related topics
Godai
Enthusiast
Enthusiast
Posts: 171
Joined: Thu Oct 05, 2006 8:13 pm

Getting angle of joypad controller using Atan2?

Post by Godai »

Hi. I can't seem to get it working. I remember it being something like atan2(joyx, joyy) but it gives negative values sometimes :)
(I know it returns radians and I need a value between 0..360)

Anyone here that can shed some light on the subject?

Thanks in advance

Update: Ahh, just forgot to add 360 if below zero

Code: Select all

; Get angle of joypad controller
*ControllerData\Angle = atan2f(bbJoyX(ControllerID-1), bbJoyY(ControllerID-1)) * (180.0 / 3.14)
    
If (*ControllerData\Angle < 0)
  *ControllerData\Angle = *ControllerData\Angle + 360
EndIf