The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

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 (159 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 (8,550 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,229 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 (85 points)
0 votes

There is a lerp_angle() function.

It will do what You are asking for.

by (24 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 Frequently asked questions and 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 [email protected] with your username.