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!

1 Answer

1

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