That’s it, the following code finds for you the shortest rotation angle from a given angle to another:

[sourcecode language='as3']

var diffAngle:Number = Math.atan2(Math.sin(angleTo – currentAngle), Math.cos(angleTo – currentAngle));

[/sourcecode]

The code was given on this forum. You’ll also find a way to do it with vectors.

Hi there,

Thanks for that snippet. It needs a Math.Abs():)

var diffAngle:Number = Math.abs(Math.atan2(Math.sin(angleTo – currentAngle), Math.cos(angleTo – currentAngle)));

Greetings!

I found one that doesn’t use trig functions; It might be more efficient. :

var diffAngle:Number = Math.min(Math.abs(Math.abs(angleTo – currentAngle) – 2*Math.PI), Math.abs(angleTo – currentAngle))

This one is for javaScript but the math behind it should apply everywhere.