This system is really confusing me. I’m rotating a turret to face an enemy sprite, I get the angle in radians with:
float angleRadians = atanf(yDifference / xDifference);
float angleDegrees = CC_RADIANS_TO_DEGREES(angleRadians);
That’s cool, now I put the enemy in several positions to see how it plotted the angles in DEGREES:
T = Turret
-45 90 45
-0 T 0
45 -90 -45
The angle for an enemy top-right of the turret is going to be the same as the angle for an enemy bottom-left, thus I’d have to have some form of condition to distinguish the 2. That wouldn’t be hard except for the fact that cocos2d’s rotational angles work like this:
45 90 135
0 T +/-180
-45 -90 -135
What do I have to do to convert the angle I calculated at the start to correctly rotate the turret with this system above?
If you use:
this should return an angle in radians which is in the range [-pi, pi].
This should fix yoUr problem.