You need to keep the previous value of rot . And add the updateRotation check, if previousRot is to the left of 360 degrees, and rot is to the right of 360 degrees, then we did 1 round and you need to stop the rotation.
Sample code for a clockwise case
if (previousRot >= 300 && previousRot <= 360 && rot >= 0 && rot <= 60) { rot = 359.99; // or here can be 360' }
For the case counterclockwise this is almost the same, but the values ββchange
if (previousRot >= 0 && previousRot <= 60 && rot >= 300 && rot <= 360) { rot = 0; }
This code will stop rotation. From the beginning, previousRot should be 0 for the case clockwise and 359.99 for counterclockwise
Another approach is to add another variable to store the total angle traveled. From the beginning, traveledAngle should be 0. And if you rotate clockwise, you need to increase it by the difference between rot and previousRot . When rotating counterclockwise, decrease it by the same value.
traveledAngle += rot - previousRot;
When traveledAngle becomes more than 360 Β°, you need to stop the clockwise rotation, and when it becomes less than 0, you need to stop the counterclockwise rotation.
vasart
source share