Sprites only rotate by 90 degrees
Hey Everyone,
In my game I have a sprite representing an enemy player. The enemy uses a basic chase algorithm to chase my player. He is able to easily follow the player however the rotation seems odd. It will only rotate in 90 degree chunks, not allowing for smooth rotation.
Ex: If I am below the enemy, he is facing straight down. As soon as I am more to the right than I am below, he will face straight right.
I use the same code in my player controller to get the player to smoothly rotate to face the mouse with no issues. Any ideas?
//Move towards target position (either player or waypoint or fleepoint)
Vector3 toTarget = moveToPoint - transform.position;
toTarget.Normalize ();
Quaternion rot = Quaternion.LookRotation (toTarget, Vector3.forward);
transform.rotation = rot;
//Zero out X and Y rotation since this is 2d
transform.eulerAngles = new Vector3 (0, 0, transform.eulerAngles.z);
if (GetComponent<Rigidbody2D> ().velocity.magnitude < maxspeed)
GetComponent<Rigidbody2D> ().AddForce (toTarget * speed);
http://docs.unity3d.com/ScriptReference/Quaternion.LookRotation.html
pick a new axis for your lookrotation
What would you suggest?
I'm pretty sure I am choosing the correct axis. The direction of 'up' in my 2D game is Vector3.forward.
Your answer
Follow this Question
Related Questions
2d rotate sprite when jumping and falling in C# 1 Answer
How do I get the current active camera? 2 Answers
Sprite gets rotated when Joystick Y at 1 or -1? 0 Answers
Image not rendering with script attached 1 Answer
[Beginner Question] Loading, Destroying and Replacing UI Background Sprites (2D) 0 Answers