- Home /
Get Rotation Around transform.up
how to get the GameObjects rotation around transform.up
im using transform.Rotate(Vector3.up, mouseInput.x);
to rotate the GameObject
I dont care is the rotation is a normalized Vector3
, quaternion
, or float
Answer by olejuer · Jan 17 at 08:43 AM
[EDIT: replaced manual calculation with Vector3.SignedAngle()]
Hi,
you probably want to look at Vector3.SignedAngle
However, this is actually not easy to answer, because it is not 100% clear, what angle you mean. The angle between what two axes? The problem with the euler representation of rotations by a series of rotations around local axes (like in your illustration), is that there are multiple ways to reach the same result. Check out the gimbal lock problem https://en.wikipedia.org/wiki/Gimbal_lock .
I assume you may want the angle Vector3.SignedAngle(Vector3.foward, transform.forward, transform.up)
, but I am not sure. Maybe it's rather Vector3.SignedAngle(Vector3.foward, transform.forward, Vector3.up)
what you want.
Hope this helps.
It almost works but the angle is less precise the more the gameobject is rotated. I think this is because Vector3.foward dose not change with the local x or z axis and transform.forward changes with all the gameobject rotation so the more rotated the player is the less accurate the angle is
There really is no answer to your question, because of the gimbal lock problem. You first need to exactly specify which angle you want to measure.