Converting PyGame 2 axis joystick float to 360 angle

  • #1
archieab
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: 345

Answers and Replies

  • #2
36,026
12,926
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
archieab
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.
 

Suggested for: Converting PyGame 2 axis joystick float to 360 angle

  • Last Post
Replies
9
Views
28K
  • Last Post
Replies
2
Views
2K
  • Last Post
Replies
16
Views
8K
Replies
6
Views
902
  • Last Post
Replies
4
Views
2K
  • Last Post
Replies
6
Views
5K
  • Last Post
Replies
7
Views
2K
  • Last Post
Replies
18
Views
5K
  • Last Post
Replies
12
Views
889
Replies
1
Views
7K
Top