Help me realize an idea

I’m making a 2D platformer in Godot. I have an enemy and a player. The enemy has Area2D and I need the enemy to chase the player when the player enters Area2D. How to make it?(Sorry for my English)

  • Godot 3.5 example, should also work in version 4.
  • without Area2D, distance between 80 and 400
var moveSpeed : int = 150
var attackDist : int = 80
var chaseDist : int = 400
onready var target = get_node("/root/MainScene/Player")

func _physics_process(delta):
	
	if target == null: return
	var dist = position.distance_to(target.position)
	
	if dist > attackDist and dist < chaseDist:
		var vel = (target.position - position).normalized() 
		move_and_slide(vel * moveSpeed)