0 votes

i want an object to look at the position of the player (the player in my game doesn't move)

I have the information of the location of the player but the object does

player_pos = $"/root/Global".player.get_position()

can anyone help me to covert the player position to an amount of degrees to turn to point towards

in Engine by (58 points)

1 Answer

+1 vote

The movement from the point A to B is B-A.
You can then replace the resulting Vector with it's normalized() form, to make it of length 1.
With that, you get the angle in radians using acos() on the Vector's x, see Unit Circle. Multiply the value by -1 if y is negative
Finally, radians can be converted into degrees using rad2deg().

by (2,634 points)
edited by
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.