0 votes

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?

asked Apr 14 in Engine by DarkLord (12 points)

1 Answer

0 votes

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

answered Apr 14 by supper_raptor (667 points)
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.