Magnus2552

08-05-2014, 02:53 PM

Hello, I want to convert the Stick's horizontal and vertical state values to a rotation (0°-360°) value.

I need this for my skillgame, where the player should set a direction using the right stick (the direction is set via OPE, so I need a rotation value). If I only would use the Stick's own events, then there only would be 8 directions that you can point to. But I want smooth rotation, so I need the horizontal and vertical values of the stick.

I know, that I need the trigonometric functions (http://en.wikipedia.org/wiki/Trigonometric_functions) for this (arcsin for horizontal and arcsin for vertical), but there are some problems:

First of, the arcsin or arccos return only correct values in specific rotation areas, for example arcsin(0) is equal to 0° AND to 180°, but arcsin will always return 0°, also if 180° would be correct. (There are multiple x values, that belong to one y value)

Maybe some math genius here has a equation that somehow combines them? :)

The bigger problem: The sticks return values from -3 to 3, depending on how far the stick was moved. So, if you just would divide the value by 3 and then pass it on to the arcsin or arccos, it will only work if the stick is pressed at maximum to the edge. But whenever the stick is somewhere between 0 and ±3, the arcsin or arccos will return false values, because sin(degree)^2 +cos(degree)^2 was not equal to 1.

I hope you understand, what I mean and hopefully someone has a solution to this? :)

Thanks for everyone, trying to help me; I hope that I did not describe my problem too complicated :confused:

Currently, its only glitching around and I hope that someone has a solution, because only 8 directions would be very lame. :)

I need this for my skillgame, where the player should set a direction using the right stick (the direction is set via OPE, so I need a rotation value). If I only would use the Stick's own events, then there only would be 8 directions that you can point to. But I want smooth rotation, so I need the horizontal and vertical values of the stick.

I know, that I need the trigonometric functions (http://en.wikipedia.org/wiki/Trigonometric_functions) for this (arcsin for horizontal and arcsin for vertical), but there are some problems:

First of, the arcsin or arccos return only correct values in specific rotation areas, for example arcsin(0) is equal to 0° AND to 180°, but arcsin will always return 0°, also if 180° would be correct. (There are multiple x values, that belong to one y value)

Maybe some math genius here has a equation that somehow combines them? :)

The bigger problem: The sticks return values from -3 to 3, depending on how far the stick was moved. So, if you just would divide the value by 3 and then pass it on to the arcsin or arccos, it will only work if the stick is pressed at maximum to the edge. But whenever the stick is somewhere between 0 and ±3, the arcsin or arccos will return false values, because sin(degree)^2 +cos(degree)^2 was not equal to 1.

I hope you understand, what I mean and hopefully someone has a solution to this? :)

Thanks for everyone, trying to help me; I hope that I did not describe my problem too complicated :confused:

Currently, its only glitching around and I hope that someone has a solution, because only 8 directions would be very lame. :)