- Home /
Consult the manual and hit the tutorials or search pre-existing material on Unity Answers.
[2D] How do you rotate a 2D sprite left and right with C#?
I've only been able to rotate the sprite along it's Y-axis with Vector3 and Vector2, which has not been working. It's been a long time since I last worked with Unity so I'm a little (lot) rusty.
If your view is true top-down, then negative z is your sprite's upwards vector. That means that such a sprite rotates left and right with it's z axis.
If you game uses a sideview, then the y axis is your sprite's upwards vector.
You can use transform.eulerAngles to change any axis xyz values. If you want to flip sprites, you just invert the x scale of the sprite.
Please read the $$anonymous$$anual for basics. It is updated, you know.
Answer by Viaticum · Apr 26, 2016 at 09:06 AM
@SebastianScaini As I understand and have used, 2D rotation happens along the Z axis by default, be it through the animator or code. Try passing Transform.Rotate a Vector3 with your desired angle (perhaps multiplied by Time.deltaTime) in the Z axis.
Answer by mohammad-alavi-74 · Apr 26, 2016 at 07:56 AM
you may want to look at this documentation:
http://docs.unity3d.com/ScriptReference/Transform.Rotate.html
Follow this Question
Related Questions
Finding the centre of two touches 2 Answers
Quaternion Rotate Towards Y Value 1 Answer
Sprite "face" second sprite only on Z axis 2 Answers
2D lock x,y rotation to look at target 2 Answers
Mirroring sprite around arbitrary axis causes collision issues 0 Answers