So I have this code to rotate a ship so it faces the player in a 2D game (all in Z plane):
Quaternion desiredQuaternion = Quaternion.LookRotation(-desiredVector, -Vector3.forward);
selfTransform.rotation = Quaternion.Slerp (selfTransform.rotation, desiredQuaternion, Time.deltaTime * turnSpeed);
desiredVector is the vector from the ship to player, selfTransform is the transform of the ship (caching), and turnspeed is the float controlling the turn speed.
The ship rotates correctly and faces the player, but whenever it passes straight up or down, it locks to that angle until the vector is at least 45 degrees or so past.
↧