Converting PyGame 2 axis joystick float to 360 angle

  • #1
2
0
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

  • Demo.png
    Demo.png
    15.2 KB · Views: 274

Answers and Replies

  • #2
35,356
11,680
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
27K
Replies
4
Views
1K
  • Last Post
Replies
2
Views
3K
Replies
6
Views
709
  • Last Post
Replies
16
Views
8K
Replies
6
Views
4K
Replies
12
Views
735
Replies
18
Views
4K
Replies
1
Views
7K
Replies
4
Views
1K
Top