0 votes

Hello! I've been working on a simple enemy for my game that follows a path (using a navigation mesh) to reach and attack the player. The enemy is moving nicely, however it doesn't rotate (and can't attack the player from all directions since it only attacks forward).

I know it's more of a math question than programming itself.

Godot version 3.4.4
in Engine by (49 points)

1 Answer

+2 votes
Best answer

The easiest way to do it is look_at() function. Add it to the _physics_process of the enemy's code and it will constantly rotates to the player. Like this:

func _physics_process(delta):
    look_at(player.translation, Vector3.UP)

It only works if enemy faces to the -Z axis.

by (652 points)
edited by
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 Frequently asked questions and 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 [email protected] with your username.