- Home /
Duplicate Question
Unity has a mind of its own on rotation
Is there some logical reason why when my script says: object.transform.rotation.x = 90;
then the object's rotation on the x axis will be all sorts of things like 180, but not 90?!
I'm going crazy trying to figure this out!
Also I tried transform.localRotation but that doesn't work either
Of course Unity has a $$anonymous$$d of it's own. Unity wouldn't want to depend on our $$anonymous$$ds. ;-) Your issue is that transform.rotation is a Quaternion...a 4D, non-intuitive object, and unless you have a firm grounding in Quaternions, you shouldn't be addressing the individual components of (x,y,z,w). You can use Transform.eulerAngles to assign angles, but the reference warns to never assign the axes individually (i.e. don't do transform.eulerAngles.x = 90;). You need assign all three in a Vector3. Plus there are multiple eulerAngle representations for any given rotation, and Unity can change the representation on you. So you cannot depend on any specific value when reading the values. $$anonymous$$eep and manipulate your own Vector3 and treat eulerAngles as write-only.
Since this problem comes up so frequently and has been answered so many time, I'm going to put my answer as a comment and close this question as a dup. If you have trouble using eulerAngles, post a new question with your script.
Answer by Eric5h5 · Jul 24, 2013 at 08:51 PM
Transform.rotation is a 4D quaternion. Rotation.x is not the X axis, and it doesn't use degrees, it uses normalized values from -1.0 to 1.0. Don't mess with quaternions unless you understand them. Look up Transform.eulerAngles instead, but pay attention to the part of the docs where they tell you not to set one axis by itself.
Follow this Question
Related Questions
Flip over an object (smooth transition) 3 Answers
accessing an array of rigidbodies at once? c# 2 Answers
Shoot an object and have it move based on rotation 1 Answer
Rotating a Prefab? 3 Answers