How do I convert an angle from Unity to an angle on the (mathematics) Unit Circle?
In Unity the angle at 0 degrees is pointing up and to rotate this angle 360 degrees we rotate it clock wise.
This is quite different from the unit circle used in mathematics. The unit circle has 0 degrees pointing right and to rotate it 360 degrees we rotate it counter clock wise.
Ultimately what I want to do is to create a unit vector from the rotation of a GameObject
's forward direction.
If you wanted a unit vector of the transforms forward direction, could you not just use transform.forward?
EDIT: actually never tested if this transform.forward is normalised in worldspace or not, I have always assumed so, but if you you could always just normalise if just in case.
all of the transform direction vectors are normalized and in world space.
Answer by jahames · Jan 26, 2017 at 01:02 AM
After an hour of scratch work and testing I came up with a solution that I think sovles my problem.
// new algo
angle += 90;
angle -= angle * 2 + 180;
// convert degrees to radians
angle *= Mathf.PI / 180;
float deltaX = Mathf.Cos (angle) * magnitude;
float deltaZ = Mathf.Sin (angle) * magnitude;
vector3 = new Vector3 (deltaX, 0f, deltaZ);
Note that the angle
is gameObject.transform.rotation.eulerAngles.y
in my code.
You don't really use this code as it is, do you? -.-
Those two lines
angle += 90;
angle -= angle * 2 + 180;
angle = 90 - angle;
Instead of
angle *= $$anonymous$$athf.PI / 180;
it's usually better to use
angle *= $$anonymous$$athf.Deg2Rad;
as it's more descriptive.
To be precise,
angle *= $$anonymous$$athf.Deg2Rad;
is also faster other than more descriptive :P
Your answer
![](https://koobas.hobune.stream/wayback/20220612105453im_/https://answers.unity.com/themes/thub/images/avi.jpg)