Hello, I am having a simple problem I cant quite sort out. I have a sprite that is being rotated to point towards the mouse position. I have this all working so far with degrees, 0-360 for both the mouse and object. My problem is when I come to the transition, when the angle changes abruptly from 0 to 360 degrees.
Here is an image I made of the problem
I’m pretty sure that I need to add another condition to both if statements, probably an OR, but I cannot seem to figure out the correct condition.
if (degreesToTheMouse > ship.angleInDegrees) {
ship.turnRight();
}
if (degreesToTheMouse < ship.angleInDegrees) {
ship.turnLeft();
}
public void turnRight() {
angleInDegrees += rotationSpeed * Gdx.graphics.getDeltaTime();
if (angleInDegrees >= 360) {
angleInDegrees = 0;
}
}
public void turnLeft() {
angleInDegrees -= rotationSpeed * Gdx.graphics.getDeltaTime();
if (angleInDegrees <= 0) {
angleInDegrees = 360;
}
}
I have tried working with difference between the two angles, rather then working with the comparision of them, but I run into the same problem. (mouseAngle - shipAngle) and (shipAngle - mouseAngle) both have the same problem when the angle measurement flips from 0 to 360, or vice versa.
Can anyone offer any tips to help me? I’d greatly appreciate it.