- Home /
Help rotating an Object
I am trying to rotate a character, in a 2d world, to the left or right depending on which half of the screen the mouse cursor is on. My code is: if (Input.mousePosition.x >= Screen.width / 2) { zombie.transform.rotation = new Quaternion(0f, 270f, 0f, 0f); } else { zombie.transform.rotation = new Quaternion(0f, 90f, 0f, 0f); }
When it runs the character just rotates towards the back wall and stays there regardless of where the mouse is. I get the feeling there is an easy answer to this but I just can't find it. Thank you in advance!
Answer by Parthon · Apr 01, 2011 at 10:49 PM
No no no no no no nooooooo. Never directly set a quaternion's values.
You want zombie.transform.rotation = Quaternion.Euler(0, 270, 0); and zombie.transform.rotation = Quaternion.Euler(0, 90, 0);
Never? :p but in all seriousness, don't alter them unless you know what you're doing. They're not that complicated, but also definitely not straightforward. ;)
Yeah, I don't want to confuse people by saying that Quaternions are a 4-dimensional representation of a rotation. That's why the values don't mean angles
Your answer
Follow this Question
Related Questions
Rotate "ghost object" then instantiate object with that rotation 1 Answer
Locking onto enemies with the third person controller 2 Answers
How rotate a gameobject in Y axis using the mouse position at screen? 1 Answer
How rotate only z axis of Gameobject (2D) 1 Answer
Rotate a gameobject like car tire 2 Answers