- Home /
2D rotation question
I'm using this code to make my gameobject rotate toward a target:
transform.right = target.position - transform.position;
The problem is that my game is viewed from the side and once rotated past 90 or below -90 the sprite is upside down, what can i do to make him flip once beyond that rotation to keep him from being upside down?
Comment
Add something like
if (transform.right.x == 90 || transform.right.x == -90) return;
I did this and it seems to work, seems a bit hacky though, i'll wait to see if there are better solutions
if (transform.rotation.z >= 0.7f || transform.rotation.z <= -0.7f )
transform.localScale = new Vector3(1,-1, 1);
else
transform.localScale = new Vector3(1,1,1);