# Rotational Limits

**URL:** <https://forum.kirupa.com/t/rotational-limits/319414>\
**Category:** flash\
**Created:** [February 19, 2011, 11:56pm UTC](https://forum.kirupa.com/t/rotational-limits/319414 "2011-02-19T23:56:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![DanDaMan](https://avatars.discourse-cdn.com/v4/letter/d/b19c9b/32.png) [@DanDaMan](https://forum.kirupa.com/u/DanDaMan)\
**Post date:** [February 19, 2011, 11:56pm UTC](https://forum.kirupa.com/t/rotational-limits/319414/1 "2011-02-19T23:56:06Z")

</div>

I’m trying to make it so that and object rotates to the mouse, but only within a specific range. In the class file for Object1, I want it to be able to rotate a maximum of 45 degrees in either direction from the rotation of Object2. So far this is all I could come up with:

```php
rotation=Math.atan2(stage.mouseY-y,stage.mouseX-x)/(Math.PI/180);
if (rotation<Object2.rotation-45) {
	rotation=Object2.rotation-45;
}
if (rotation>Object2.rotation+45) {
	rotation=Object2.rotation+45;
}

```

The possible rotations of Object2 are 0, 45, 90, 135, 180, -135, -90, and -45. The code seems to work fine if the rotations are between -90 and 90 (the right half), but because the left half goes from -179 to 180 to 179, it obviously fails. How would I accomplish the effect I want? Thanks 😃
