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?

in Engine by (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

by (736 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.
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 webmaster@godotengine.org with your username.