That's basically what i'm trying to do, make my enemy follow the player in the X (or Y axis, I'm not sure) like a lakitu from mario bros. The problem is that move_and_slide used a Vector2 so I don't know how to ONLY use ONE axis instead of two. I guess it follows 2 axes because they only move horizontally but also are stuck to the Y axis...? Some help please!

The enemy's code right now:

Try replacing lines 1-7 with this:

extends KinematicBody2D

var speed = 200
var move_direction = 1

onready var player = get_parent().get_node("Player")

func _process(delta):
	# If the player is to the right, direction is positive, otherwise its negative.
	move_direction = 1 if player.position > position else -1


func _physics_process(delta):
	if abs(position.x - player.position.x) > speed * delta:
		move_and_slide(Vector2(speed * move_direction, 0))

it should work if the script is on the enemy and the player is a sibling.

@spacecloud said: Try replacing lines 1-7 with this:

extends KinematicBody2D

var speed = 200
var move_direction = 1

onready var player = get_parent().get_node("Player")

func _process(delta):
	# If the player is to the right, direction is positive, otherwise its negative.
	move_direction = 1 if player.position > position else -1


func _physics_process(delta):
	if abs(position.x - player.position.x) > speed * delta:
		move_and_slide(Vector2(speed * move_direction, 0))

it should work if the script is on the enemy and the player is a sibling.

The problem is that the enemy node and the player node are completely separate nodes, so it doesn't work. "Parser Error: The method "move_and_slide" isn't declared in the current class."

Nevermind, I had to change the extends part. Thank you for the help!!

a year later