- Home /
Get player orientation, but only one Euler angle is non-zero
I am trying to retrieve the player orientation using the following snippet, which is run again at every frame:
Transform transform = GameObject.FindGameObjectWithTag("Player").transform;
Debug.Log("euler: " + transform.eulerAngles.x + "|" + transform.eulerAngles.y + "|" + transform.eulerAngles.z);
Unfortunately, however, only one of the Euler angles (more specifically y
) appears to be changing even though I am moving the player orientation along multiple axes. I looked into the Quaternion itself (and studied the theory of Quaternions too) but I see the same problem. Any idea what could be the problem?
Are you actually rotating the player object around multiple axes, or just translating along them?
Answer by JC_SummitTech · Mar 16, 2017 at 06:02 PM
For a player orientation having only a change in Y does make sense. It would allow the player to rotate around 360 degrees. Now if you are tilting him sideways or backwards/forward, having only the Y component change is indeed strange.
Answer by oznen · Mar 16, 2017 at 08:37 PM
I think I found a solution to my own problem. What I was looking for is the orientation of the camera, not of the player. The orientation of the player stays fixed in a direction parallel to the ground (that is why the only the y
component was non-zero), even if I am using the mouse to look e.g. in an upward direction. All I needed was to replace
Transform transform = GameObject.FindGameObjectWithTag("Player").transform;
with
Transform transform = Camera.main.transform;
Your answer
Follow this Question
Related Questions
Euler angle problems with rotation limit script 3 Answers
Get local euler angles by Quaternion 1 Answer
Rotation relations and EulerAngles's mess 0 Answers
Difference between transform.localEulerAngles and transform.localRotation=Quanerion.Euler 1 Answer
Rotating an object around the centre of its mesh, using Quarternion AxisAngle 1 Answer