# Gun rotation according to mouse

**URL:** <https://forum.kirupa.com/t/gun-rotation-according-to-mouse/294502>\
**Category:** flash\
**Created:** [August 15, 2009, 4:26am UTC](https://forum.kirupa.com/t/gun-rotation-according-to-mouse/294502 "2009-08-15T04:26:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dilpreet](https://avatars.discourse-cdn.com/v4/letter/d/51bf81/32.png) [@dilpreet](https://forum.kirupa.com/u/dilpreet)\
**Post date:** [August 15, 2009, 4:26am UTC](https://forum.kirupa.com/t/gun-rotation-according-to-mouse/294502/1 "2009-08-15T04:26:47Z")

</div>

Hey

I have done the rotation bit, but now i want to limit the rotation but i can’t do it  
this is my code -

```php
stage.addEventListener(Event.ENTER_FRAME, moveArm)
function moveArm(e:Event):void
{
	//Grab the angle
	var angle:Number = Math.atan2 (mouseY - arm.y, mouseX - arm.x);
	//Rotate the gun, convert angle (in radians) to degrees.
	arm.rotation = angle * 180 / Math.PI;
	
	if (arm.rotation < -90 ||arm.rotation > 30)
		{
			stage.removeEventListener(Event.ENTER_FRAME, moveArm)
		}
		else
		{
			stage.addEventListener(Event.ENTER_FRAME, moveArm)
		}
}

```

this code work but once the mouse rotates past 30 Degrees it removes the event listener which is fine it stops the gun moving, but if you move your mouse again it doesn’t add the event listener and the gun is just stuck their.

Any ideas thanks
