This is in GD4.0, working in 2D
I want to turn a physics object (or really anything with rotation) towards a certain angle, and because angle-related variables such as rotation
and the output of Vector2.angle()
can be both positive and negative, as well as the fact that TAU
is closer to 0 than TAU/2
, it's very painful to try to figure out which way I should turn for the fastest way to reach a desired orientation.
By the way, I know about look_at
, but it doesn't help when trying to turn a physics object by applying a torque (rotational force), because it doesn't tell me which way I should be applying that torque.
So, if given a desired direction and current rotation of an object, how can you find out which direction the torque should be applied? Presumably the function looks like this:
func get_turn_direction(current_angle, desired_angle) -> int: #output is -1, 1 or 0
...