Python Forum
[PyGame] Converting PyGame 2 axis joystick float to 360 angle - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Game Development (https://python-forum.io/forum-11.html)
+--- Thread: [PyGame] Converting PyGame 2 axis joystick float to 360 angle (/thread-13050.html)



Converting PyGame 2 axis joystick float to 360 angle - archieab - Sep-25-2018

I would like to convert my joystick's two axis float (horizontal and vertical) to a 360 angle that can be used to set a players direction in my game. From my research, I've found the best route to take is using Atan2.

Variables:
self.rot = 0
horaxis = joy1.get_axis(0)
veraxis = joy1.get_axis(1)
Demonstration Diagram: you are correct, it is drawn in MS Paint
[Image: 6Ugnk.png]

Absolutely any suggestions/snippets for the code would be amazing!


RE: Converting PyGame 2 axis joystick float to 360 angle - archieab - Sep-26-2018

Aha! About 2 hours after posting this, I found a solution online.