I've programmed a shooter thingy to rotate towards the mouse and fire missiles on mouse clicks. Now what I need to do is limit the rotation of the shooter thingy so it doesn't rotate beyond a minimum angle and a maximum angle.
Well, what I do in my game is just denying the atribuation of the angle between mouse and the weapon to the weapon's angle itself when the limits are reached. In my game, I'll weapons are nested inside the hero, that's why I get the angle like that:
//All this is done inside your ENTER_FRAME envent which rotation //your weapon
//Calculates the position of the weapon and gets its angle this.angleBetweenMouseWeapon = Math.atan2(parent.mouseY - this.y, parent.mouseX - this.x); //Transform from radians to degrees this.angleBetweenMousePistol *= (180/Math.PI);
//Now, if the limits are reached, in this case I did between 45 //degrees and -45 degrees you do the atribuations if (angleBetweenMouseWeapon <= 45 && angleBetweenMouseWeapon >= -45) { //rotation Weapon; weapon = angleBetweenMousePistol; }