Im trying to rotate an object 90 degrees to the left but instead of rotating straight left it rotates 270 degrees to the right.

Here's the part of the code which controls the rotation:

rotationDestination = new Vector3(60, 270, 0);
if (Vector3.Distance(transform.eulerAngles, rotationDestination) > 0.2f) {
  transform.eulerAngles = Vector3.Lerp(transform.rotation.eulerAngles, 
                                       rotationSpeed * Time.deltaTime);

If I try to make the Y axis -90 a.k.a (60, -90, 0) then it rotates constantly to the left.

How do I make it rotate straight to the left (90 degrees) ?

Thank you.


1 Answer 1


You can use Quaternions instead of Euler Angles to solve this.

transform.rotation = Quaternion.Lerp(transform.rotation, 
    Quaternion.Euler(rotationDestination), Time.deltaTime * rotationSpeed);

If you want to test distance still, you can use...

if(Quaternion.Angle(transform.rotation, Quaternion.Euler(rotationDestination)) > 0.2f)

I'd suggest you make 'rotationDestination' into a quaternion too. Just so that you're not converting back and forth between quaternions, and euler angles as much.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .