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?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | 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); } |