How to rotate a cube in unity?
I've been trying to work out how to do this for an hour now. What I'm trying to do is when a person picks up an object (I'll call it the cube for now) then the cube should rotate to 0, 0, 0 on the local axis.
I have this right now and it's not working. transform.localEulerAngles = new Vector3(0, 0, 0);
And I tried going on multiple documentation, forums, and tutorials. Can anyone help me with this? (By the way, does the cube getting parented to an empty game object have anything to do with this?)
Answer by Bunny83 · Jul 15, 2020 at 08:20 PM
The line:
transform.localEulerAngles = new Vector3(0, 0, 0);
Will certainly rotate the object to local euler angles rotation of 0, 0, 0. Keep in mind that local rotation means it's local to it's parent. So by setting the localEulerAngles to zero the child will have the same rotation as the parent.
Your initial condition was that you want to rotate it's local rotation to 0,0,0. That's exactly what happens. If that's not what you want, then your initial condition is already wrong.
Thank you so much - this helped a lot:) - I found out that i could also do transform.rotation = new Quaternion(0, 0, 0, 0);
. Last time i just didn't add the w component.
Your answer
Follow this Question
Related Questions
How to make a gameobject rotate coninously on key press? 1 Answer
problem of rotate joint of hands 0 Answers
Make GameObject rotate around another around random axis but with fixed distance 0 Answers
ROTATION STOPS when i move the char on the air! 0 Answers
Ask some problem about rotation, quaternion and angle 0 Answers