I have been searching the web for a bit trying to find a solution… And after going through every related post in stackoverflow I still can’t find a working solution… This looked promising but didn’t work… http://stackoverflow.com/questions/2150136/slowly-rotate-an-object-towards-another-object
View the issue here… Move the mouse around the object and see the glitch where the object tries to rotate 360 when the mouse is to the left crossing the zeroline? http://designermichael.com/kirupa/Main.html
My code:
//Angle to mouse
var thrustAngle:Number = gameMath.angleBetweenPoints(new Point(Game.gameMouseX,Game.gameMouseY),new Point(rocketSprite.x,rocketSprite.y));
if (thrustAngle < rocketSprite.rotation) {
physicsBody.SetAngularVelocity(-1);
} else if (thrustAngle > rocketSprite.rotation) {
physicsBody.SetAngularVelocity(1);
} else {
physicsBody.SetAngularVelocity(0);
}
//Function
public static function angleBetweenPoints(Location:Point, Target:Point):Number {
var Angle:Number = Math.atan2(Location.y - Target.y,Location.x - Target.x);
var Degrees:Number = radToDeg(Angle);
return Degrees;
}