I am having an issue where `eulerAngles.y` is returning a Y rotation value that jumps when I move the character head up and down (X axis).
So when I move the head up (above green line), `eulerAngles.y` returns 0. But when I move down (below green line), `eulerAngles.y` returns 180. Keep in mind that moving the head up and down rotates around the X axis.
# Check out the [Video (YouTube)](http://youtu.be/vypv8ubgnmI) explaining the issue.
You can see in the second picture that the local transform and rotation for the head are not default and are a bit rotated.
![Head Up Down][1]
![Head Transform][2]
The Lines coming from the head are just gizmos created as so:
Gizmos.color = Color.red;
Gizmos.DrawLine(headTransform.position, headTransform.position + headTransform.up*3);
Gizmos.color = Color.green;
Vector3 forward = headTransform.up;
Gizmos.DrawLine(headTransform.position, headTransform.position + (new Vector3(forward.x, 0, forward.z)*3));
I know that [`eularAngles`](http://docs.unity3d.com/Documentation/ScriptReference/Transform-eulerAngles.html) has a rotation order but how do I get the Y rotation in world space that I can apply to any object and it will point in the same direciton.
----
My goal is to make the body turn to where the head is looking and have the head counteract the body motion so they are aligned. Although I am having other issues, this is just one I am stuck on why this is happening. When I add the code below, the character just spins around and around.
// Make the body rotate to where our head is pointing
bodyTransform.eulerAngles = new Vector3(bodyTransform.eulerAngles.x, headTransform.eulerAngles.y, bodyTransform.eulerAngles.z);
// Counter-act the body by rotating the head back into place
headTransform.eulerAngles = new Vector3(headTransform.eulerAngles.x, bodyTransform.eulerAngles.y, headTransform.eulerAngles.z);
[1]: http://i.imgur.com/I097K5q.gif
[2]: http://i.imgur.com/BA1bHnf.png
↧