Why do the enemys always go to a werid position when they follow the character?

I would bet your enemy or player are not centered at their scene’s origin, could you show the enemy and player scene? Your math is also mixing global_position and position which could be problematic if your main scene is offset from it’s origin.

lerp is probably a bad function to call, especially on a CharacterBody2D. Your physics process function was closer to a good script, just make sure to use velocity and move_and_slide() as it’s a CharacterBody2D

func _physics_process(delta: float) -> void:
	var difference: Vector3 = player.global_position - global_position
	var direction: Vector3 = difference.normalized()

	if difference.length() > 3:
		velocity = direction * speed
	else:
		velocity = Vector3.ZERO

	move_and_slide()

Make sure to format your pastes

2 Likes