0 votes

Does the atan2() function uses the global X axis? If so, how can I use the local object X axis in order to properly steer it?

Godot version 3.3.3
in Engine by (28 points)

1 Answer

0 votes

The function simply returns the arc tangent of the values you give it. If you are trying to calculate the bearing to a vector relative to a different vector, you can either use Vector.angle_to_point() or subtract the vectors and calculate the atan2 between the result's coordinates.

by (795 points)

I did the second approach, and since it returns the angle between the passed vector (in this case, "target minus position") and the X axis, I expected it to return in local coordinates. Thing is, it just dont change after rotating the object in place (since the position vector hasn't changed at all and the angle is between this vector and the global X).
I thought about sum or subtract this angle on the object rotation, so it would "apply" to his own directions, however, i think it require some math coding. Anything I may be missing?

You mean you want the angle between one vector and another? Vector2.angle_to() might come in handy.

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.