- Home /
Why is the rotation values I am accessing wrong?
I am trying to get the y value of the transforms rotation for a gameobject with name "turret" i tried to use a code (c#) like this to do it, but the values it gives me are obviously wrong, telling me it is 30 when it should be 90.
float ang = GameObject.Find("turret").transform.rotation.y;
I'm not sure if this is enough information for anyone to help me, but please help! Its bothering me that I can't seem to fix this.
Answer by robertbu · Feb 21, 2013 at 05:59 AM
"transform.rotation" is a Quaternion and you should not use the x,y,z,w values directly unless you understand Quaternions. Use transform.eulerAngles instead.
thanks, I had forgotten that quaternions weren't just regular angles.
Answer by Eric5h5 · Feb 21, 2013 at 06:02 AM
They're not wrong at all. Transform.rotation is a 4D quaternion, which does not use degrees, nor do the x/y/z elements directly correspond to the x/y/z axes. You can try using Transform.eulerAngles, but reading one particular axis doesn't necessarily give results you might expect either since there's more than one valid way to convert quaternions to eulerAngles.
Your answer
Follow this Question
Related Questions
How to keep a Gameobject in the same position after a transform.Rotate? 2 Answers
Neutralising child rotations -> Parent 1 Answer
Adding Rotation to a Gameobject 1 Answer
Rotating an object in position 2 Answers
How to rotate the game object 0 Answers