How to move enemy? (2D)

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

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.

:bust_in_silhouette: Reply From: quijipixel

(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