# Rotation problem

**URL:** <https://forum.kirupa.com/t/rotation-problem/327925>\
**Category:** Uncategorized\
**Created:** [April 6, 2012, 2:45am UTC](https://forum.kirupa.com/t/rotation-problem/327925 "2012-04-06T02:45:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![drpelz](https://avatars.discourse-cdn.com/v4/letter/d/c68b51/32.png) [@drpelz](https://forum.kirupa.com/u/drpelz)\
**Post date:** [April 6, 2012, 2:45am UTC](https://forum.kirupa.com/t/rotation-problem/327925/1 "2012-04-06T02:45:44Z")

</div>

Hi,

this problem drives me crazy and I hope someone can help me out with this:

I got an object (called tempEnemy) which is flying around and shooting.  
The problem is that I can’t keep the value tempEnemy.rotateTo positive, i.e.  
it shall be between 0 and 359 degrees. Currently rotateTo ranges from:  
rotateTo \< 0 (bug) && rotateTo \> 0 && rotateTo \> 359 (bug).

As mentionend before I want rotateTo between 0 and 359 degrees.

Can someone help me out with this problem please? I’m very poor in trig…

```auto

tempEnemy.dX = tempEnemy.destX - tempEnemy.x;
tempEnemy.dY = tempEnemy.destY - tempEnemy.y;
	
//I added 180 because my tempEnemy object was looking and shooting to the wrong direction
tempEnemy.rotateTo = (toDegrees(getRadians(tempEnemy.dX, tempEnemy.dY))) + 180;	
						
if (tempEnemy.rotateTo > tempEnemy.frame + 180) tempEnemy.rotateTo -= 360;
if (tempEnemy.rotateTo < tempEnemy.frame - 180) tempEnemy.rotateTo += 360;
													
tempEnemy.incFrame = int((tempEnemy.rotateTo - tempEnemy.frame) / tempEnemy.rotateSpeed);

```
