How do make enemy look at player when following it.

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

My enemy follows my player using Navigation 2D. But problem is my enemy doesn’t look at my player when following it. How do i make it look at my player?

:bust_in_silhouette: Reply From: supper_raptor

To make the enemy look at player, you need to set rotation of your enemy.
You need to use vector algebra here,

#enemy.gd
func _process(delta):
	#position of player minus enemy position will give us direction
	Vector2 dir = player.position - position

	#get angle from direction (Note roation is in radians)  
	rotation = dir.angle()

if it is not pointing towards player add or subtract 1.57 (90 degrees in radian) to rotation