- Home /
Convert vertical angle to horizontal angle (C#)
Hello, I am using the control freak plugin (http://forum.unity3d.com/threads/control-freak-the-ultimate-virtual-controller-for-unity-mobile.203823/) in my game.
I want to rotate my character in the direction the the user is moving the touch stick.
This touch stick is oriented verticaly, but I would like to convert this angle to an horizontal angle.
Here is an image for you to understand better:
I'm completly confused and don't know from where to start to obtain the good new angle.
Thank you for your time :)
Note if you have the Joystick position (and if it is oriented like most joysticks), you can get the angle by:
var angle = $$anonymous$$athf.Atan2(stick.y, stick.x) * $$anonymous$$athf.Rad2Deg;
Then the joystick is probably not oriented like most joysticks, because the angle returned by your functions is equal to the one returned by the joystik's angle function (the first image)
Anyway thank you for the tips
Answer by GameVortex · Nov 02, 2014 at 09:26 PM
This is regular math. By looking at the top angles we see that angles are offset by -90 degrees, but they have also opposite rotation directions. So we can add -90 to offset the angle and then multiply it by -1 to switch the direction.
Using your solution 0 would become -90, because (0 + 90)*(-1) = -90.
Or I missunderstood something?
That makes sense, and is working well, please edit your answer with -90 so I can accept the answer. Thank you ;)