How do you get a object to point to another object?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Curiosity93

I’m new to Godot and want to add an enemy that shoots bullets at the player. I have the coordinates of the player ($“/root/Global”.player.get_position()), but I am not sure how to translate that into a direction toward the player. Any help is appreciated.

:bust_in_silhouette: Reply From: citizenl

Easy do like this:

var dir = enemy.global_position.direction_to(player.global_position)
enemy.rotation =  dir.angle()

Of course you can also use a simpler method, they are essentially the same

enemy.lookat(player.global_position)

see lookat doc

2 Likes