How do u get something to rotate towards mouse

2 posts

Flag Post

how do u get a MC to rotate towards the mouse a bit at a time? does any one have the code

 
Flag Post

This will turn mc towards the mouse by a maximum of 5. This assumes the mc is drawn facing the right. If it’s facing up, just add 90 to angle.

	// Find the angle towards the mouse
	var angle:Number = Math.atan2(mc._parent._ymouse - mc._y, mc._parent._xmouse - mc._x) * 180 / Math.Pi;
	var difference:Number = angle - mc._rotation;
	// Make sure the difference is between -180 and 180 so it can be limited easily
	if (difference < -180) difference += 360;
	if (difference > 180) difference -= 360;
	// Limit the movement to 5 in either direction
	difference = Math.max(-5, Math.min(5, difference));
	mc._rotation += difference;