0 votes

How can i move the enemy towards the player? I'm learning godot and programming about a month. So far i got the player movement (kinematicbody), 2 levels, some collective objects and a score display at the end.

SceneTree is like this:

-Level 1
-Tilemap(Child of Level 1)
-Player (Child of Level 1)
-Coins (Child of Level 1)
-Enemy (Child of Level 1)

Enemy is an Area2D with a sprite and a collisionshape.

in Engine by (12 points)

1 Answer

0 votes

(I'm assuming you are using Godot 3.0)
inside _physics_process of the Enemy node:

const SPEED = 100.0    
func _physics_process(delta):
    var direction = ($Player.position - position).normalized()
    var motion = direction * SPEED * delta
    position += motion
by (695 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.