area2D detects late

I’m working on a 2D platform game. Basically, there are two Nodes related to my problem, one is a character Node and uses characterbody2D, and we have an enemy node, which also uses rigidbody. There is an area in the enemy’s nodes, this area allows the player to follow him when he enters the area, or rather it should have, but when the character enters the area, at first the player is detected for a short time and moves a little, but then the player acts as if he left the area. If the player leaves area2D and enters again, the enemy always follows the player until he leaves the area, as it should. In short, while area2D does not work properly on the first entry, it works perfectly on the second entry. Where is your mistake? Thank you very much to everyone who has tried to help in advance.

The enemy codes are exactly as follows:

Extends rigidbody2D.

Var speed = 500.
var player_chase = false.
Var Player = null.

Func _on_target_body_entered(body: Node2D) → Void:
Player = body.
Player_chase = true.

Func _on_target_body_exited(body: Node2D) → Void:
Player = null.
Player_chase = false.

Func _physics_process(Delta: Float) → Void:
If player_chase:
Var direction = (Player. Position - position).normalized()
Apply_central_force(direction * speed)
Print(“control”)

My guess is there’s another body entering the area and overwriting Player. Try setting a breakpoint in _on_target_body_entered

Yes, it worked and thanks to two lines of code :smiley: Let me write for those who have the same problem as me: Group control is actually enough:

if body.is_in_group(“player”):

I added this only to the parts that allow targeting the character and it worked.

Thank you very much to the person who helped

(Please forgive me if I’m using English incorrectly, I’m speaking via Google Translate)