problems with the mob

Godot Version

4.2.2

extends CharacterBody2D

var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")

var chase = false

var spd = 100

func _physics_process(delta):
	# Add the gravity.
	if not is_on_floor():
		velocity.y += gravity * delta
	var player = $"../../player/player"
	var direction = (player.position - self.position).normalized()
	if chase == true:
		velocity.x = direction.x * spd
		
	move_and_slide()

func _on_detector_body_entered(body):
	if body.name == "player":
		chase = true# Replace with function body.

Question

my mob should follow the player when he gets close enough,
but when the mob notices the player it just goes left and only left, what’s wrong?

because you use the “position” and not the “global_position”

its didnt work

Okay then put some prints in there and check if the positions make sense:

var direction = (player.global_position - global_position).normalized()
print("Player-position: ", player.global_position, "; Enemy-position: ", global_position)
print("Direction: ", direction)