Rotation direction

Hello,

in my current game project I need to rotate the camera around a certain spot.

Let’s say, my camera is currently rotated to (0,0,0) and I want to rotate it to (0,72,0). Normally I’d use somthing like:

transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(0,72,0), Time.deltaTime);

This works just fine, but now I’d also like to decide, whether the camera will rotate to this position clockwise or counter clockwise. Is there a way to make sure the camera will only rotate to the right or to the left?

I guess I need to come up with a method, which takes care of this, so any help will be greatly apprecated.

Thanks in advance.

The slerp operation rotates in the direction that will get to the target rotation most directly. This is usually what you want, but if you need to rotate through a reflex angle (ie, > 180º) then you need to break the rotation down into two angular steps, each less than 180º.

You can detect whether a slerp will rotate to the left or the right using the cross product of the two direction vectors. An example of how to do it is in this thread.

Thank you very much!