I have attempted to write some code that would allow the player to slowly rotate towards a desired rotation rather than instantly rotating the entire way. However, the player just instantly rotates anyway. Here's my code:
Where rotateSpeed = 6.
Does anyone know what I'm doing wrong?
int targetRotationAlt = targetRotation - 360;
int targetRotationAlt2 = targetRotation + 360;
boolean withinRotationRight = targetRotation < getRotation() + rotateSpeed || targetRotationAlt < getRotation() + rotateSpeed || targetRotationAlt2 < getRotation() + rotateSpeed;
boolean withinRotationLeft = targetRotation > getRotation() - rotateSpeed || targetRotationAlt > getRotation() - rotateSpeed || targetRotationAlt2 > getRotation() - rotateSpeed;
if (targetRotation < getRotation() + 180 || targetRotationAlt < getRotation() + 180 || targetRotationAlt2 < getRotation() + 180)
{
turn(-rotateSpeed);
}
else
{
turn(rotateSpeed);
}
if (withinRotationRight && withinRotationLeft)
{
setRotation(targetRotation);
}


