0 votes

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?

in Engine by (126 points)

4 Answers

0 votes

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.

by (6,496 points)
0 votes

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.

if wanted_angle > rotation_degrees+180:
    wanted_angle -= 360
elif wanted_angle < rotation_degrees-180:
    wanted_angle += 360
by (3,227 points)
0 votes

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.

by (83 points)
0 votes

There is a lerp_angle() function.

It will do what You are asking for.

by (22 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.