Converting PyGame 2 axis joystick float to 360 angle

  • #1
2
0

Main Question or Discussion Point

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:
Code:
self.rot = 0
horaxis = joy1.get_axis(0)
veraxis = joy1.get_axis(1)
Demonstration Diagram: you are correct, it is drawn in MS Paint
Demo.png


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

Attachments

Answers and Replies

  • #2
34,056
9,919
From my research, I've found the best route to take is using Atan2.
So what is unclear? The atan2 function gets the x and y displacement as input, you have both.
The center could be checked with an additional if condition.
 
  • #3
2
0
So what is unclear? The atan2 function gets the x and y displacement as input, you have both.
The center could be checked with an additional if condition.
Managed to solve the issue doing some extra research. Thanks for the reply.
 

Related Threads on Converting PyGame 2 axis joystick float to 360 angle

Replies
9
Views
26K
Replies
4
Views
782
  • Last Post
Replies
2
Views
3K
Replies
6
Views
590
  • Last Post
Replies
16
Views
7K
Replies
6
Views
4K
Replies
12
Views
590
Replies
18
Views
4K
Replies
1
Views
7K
Replies
4
Views
1K
Top