I'm trying to to rotate a sprite, let's say it's a gun, to a point, by taking the smallest route possible on a 360° (right or left depending on what side the point is closer to) and I'm having a few problems.
On a circle, it jumps from 359° to 0° so I can't direcly use my target angle - current angle.
Leep in mind that I'm using SFML so it's executing the function everyframe while isRotating is true.
This is the information that is available to me :
//The angle in degrees of my sprite float currentAngle = pSprite.getRotation(); //The angle is needs to be once the rotation is over float targetAngle = float(atan2(deltaY,deltaX) * 180 / (atan(1)*4) + 180); I'm using a speed variable to increment or decrement the value of the angle every frame.
distance = Speed*Time.asSeconds(); currentAngle += distance;