title: AndEngine Smooth Rotation along Path
body: <p>I am drawing a path and move a sprite along it. Now i want the sprite to always look into the driving direction after each waypoint.
  With this Code i can just set the Direction(non smooth). getTargetAngle returns the new rotation angle.</p>
  
  <pre><code>float angleDeg = getTargetAngle(sprite.getX(), sprite.getY(), targetX[pWaypointIndex + 1], targetY[pWaypointIndex + 1]);
  sprite.setRotation(angleDeg);
  </code></pre>
  
  <p>Now i can do it smooth, except im at the turning point from -179° to 179°, where it turns along the long-path instead of the short and makes a jump:</p>
  
  <pre><code>sprite.unregisterEntityModifier(rotMod);
  rotMod = new RotationModifier(0.5f, currentAngleDeg, angleDeg);
  sprite.registerEntityModifier(rotMod);
  </code></pre>
  
  <p>I tried adding/subbing 360° to the current angle of the sprite when the absolute addition of both Angles exceeds 180°. Making the jump from -179° to 179° to a jump from 181 to 179, but this doesnt work.</p>
  
  <pre><code>if(Math.abs((float)angleDeg) + Math.abs((float)currentAngleDeg) &gt; 180) {
  if (currentAngleDeg &lt; 0) {
      currentAngleDeg+=360.0f;
  } else {
      currentAngleDeg-=360.0f;
  }
  </code></pre>
  
  <p>getTargetAngle:</p>
  
  <pre><code>public float getTargetAngle(float startX, float startY, float         targetX, float targetY){
  
      float dX = targetX - startX;
      float dY = targetY - startY;
      float angleRad = (float) Math.atan2(dY, dX);
      float angleDeg = (float) Math.toDegrees(angleRad);
      return angleDeg;
  }
  </code></pre>