My method takes Horizontal and Vertical inputs from the controller, each with a value between 1 and -1.
I need to be able to take this and get a Euler Angle, but also take a Euler angle and convert it back into a Horizontal and Vertical input.
My method seems accurate for converting the x,y, but my “checkAngle” variable always seems off no matter what i try.
I have no idea what i am doing:
var myAngle = myRot.eulerAngles.y;
float horz = Horizontal;
float vert = Vertical;
float length = (horz * horz + vert * vert);
if (length != 0.0f) {
horz /= length;
vert /= length;
}
float angle = Mathf.Atan2(vert, horz);
float checkH = Mathf.Cos(angle);
float checkV = Mathf.Sin(angle);
float checkAngle = Mathf.Atan2(checkH, checkV) * Mathf.Rad2Deg;
if (checkAngle < 0) {
checkAngle = 360 + checkAngle;
}
//vectorAngle = 45 - vectorAngle;
Debug.Log ("My angle is: " + myAngle + ", which should match: " + checkAngle);
Debug.Log("Horizontal and Vertical Input: " +Horizontal + ", " + Vertical + " inputs derived from angle: " + checkH + ", " + checkV);