Calculate the time of angle a to angle b

So I have this turret and want to hard code everything and not rely on the physics engine, and I want the turret to rotate with a constant angular velocity.

I already tried this formula:

time = (angle b - angle a) / angular velocity

This does not really work because it only works if b is greater than a. I could use the min and max functions, but it still does not work because the numbers are sometimes in the negative. Still, I can just use the absolute function, but the result that it gives me is not accurate.

Never mind, I found the formula:

time = math.abs((end angle - start angle + 180) % 360 - 180) / angular velocity

It seems that by adding 180 to the difference between the end angle and the start angle, taking the remainder of that value when divided by 360, and then subtracting 180, makes sure that the angle is always between negative and positive 180 degrees.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.