Topic was automatically imported from the old Question2Answer platform.
Asked By
Timofey
if the current degrees of rotation are, for example, 90 and I need to rotate to 0 degrees of rotation, I need the object to rotate to the left, because this is faster than if it rotated to the right. How to determine which direction it is spinning in order to reach the desired degree measure as quickly as possible?
So what you’re asking is more of a math problem. I’m not really good at visualizing stuff like this, but maybe an answer here could help. I don’t think you need to know the direction the object is currently spinning in order to find the fastest path there.
There’s a few ways of doing this but the easiest way for a single axis is to check if the end rotation is above or below the starting rotation by 180 degrees and add or subtracting 360 degrees.
the answer really depends on application one way to calculate whether you need a positive or negative rotation direction is
if self.get_angle_to(target.global_position) != 0:
turn = abs(self.get_angle_to(target.global_position)) / self.get_angle_to(target.global_position)
the abs() value divided by the actual value will result in -1 if the angle is negative or 1 if the angle is positive. you have to test if the angle is zero to avoid divide by zero error.