Enemies which chase only after chasing and don't lose agro!

Godot Version



How do I create an enemy that chase only if I get in its raycast because I can’t for the love of God understand state machines😭 help me!!

If you want them to never stop chasing then you need only to track the first time they see a target. If raycast hit: chase target. Could you show what you’ve tried before?

1 Like

I deleted that code :disappointed_relieved:

Just use an Area2D for it. If in the Area2D, it chases, otherwise not.


func area_2d_body_entered():
chase_is_actice = true

func area_2d_body_exited():
chase_is_active = false

func _process(delta):
#your code → folloeing logic → nav agent usage recommended

You could also instantly run a moving function, I used the boolians. That is up to you though.
I will look for my code and post it here later, which worked just fine.

You need a tilemap though

But the games 3d

Then use an area3d


Oh, my bad.
But yeah, an Area3D will suffice as well.