Enemy AI Behaviour Feedback

Godot Version

Godot Engine v4.6.1 stable arch_linux

Using :

Problem

It鈥檚 my first time using behavior trees and advanced enemy AI so I鈥檓 not sure if I鈥檓 doing this right, that鈥檚 why I would like some feedback.

the project is in this repository : github repo

main thing I want to improve is the player detection, mainly how the AI should behave after loosing sight of the player.

Technical Details :

I did this by:
- raycast to the enemy forward
if position is valid => go there
else :
- raycast to the enemy right
if position is valid => go there
else:
- raycast to the enemy left
if position is valid => go there
else :
- raycast to the enemy back
if position is valid => go there
else : panic and abort


for now it鈥檚 roughly doing this but with some quirks and weird behaviors in between.

Showcase :

here鈥檚 a link to a showcase of the current state : youtube video

Checking raycasts in 4 directions feels like a grid-based approach, but I don鈥檛 think you have grid-based movement from looking at your repo. I think you could just check if the player is in the enemy vision cone (if you鈥檙e using those) and then one raycast to the player position.

The simplest approach when losing LoS to player (or just the default reset behavior in general) is to give each enemy a tether point they鈥檒l return to if they鈥檝e wandered too far.

A slightly more advanced reaction would be for the enemy go to the player鈥檚 last known position before giving up and resetting.


Update after watching the video: yeah, obv. not grid based. The green and red markers that spawn in鈥搘hat do they represent?

Sorry for the late replay I got a bit lost in the mountains,

For your first point, Yes the even thought the raycasting is similiar to a grid based it鈥檚 in fact not, I wanted to emulate a more natural approach without a heavy performance cost, off course more rays can be added (diagonal for instance) But I鈥檓 trying to see what works and what doesn鈥檛 for now.

As for the red and green Boxes, I鈥檓 sorry I should鈥檝e explained those, they are merely for debugging purposes only, upon raycast if the the found point is valid a green Box is spawned in it鈥檚 position, else a red one is spawned.