how do i get my enemy to aim at the player

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

I am very new to godot and I have been trying to figure this out for a few hours, i’ve tried multiple different methods but every time it has just a tiny problem I have no idea how to fix.

:bust_in_silhouette: Reply From: Redical

Hello!

I’m actually pretty new to Godot too, but I’m pretty sure you can do this to get the enemy to look at the player:

onready var Player = get_node(<path to player>)

var dir = Switch.position - position
rotation = dir.angle()

That would be written in the script attached to the enemy, by the way.

Here is a question that’s also relevant:
https://forum.godotengine.org/67337/how-do-make-enemy-look-at-player-when-following-it

If those don’t work, could I get some more information about what you’re trying to do?
Also, are you making a 2D game? Just checking, as 3D would be a bit more complicated.

Hope this works! :smiley: