This is a long shot, I'm sure, but I'm close to my wit's end here with my entity AI. It's a general-purpose AI that is used for both enemies and allies, with a simple bool designating whether they're friendly or not.
Currently, there are these states:
- idle (not doing anything, ready to move to either roam or follow)
- roam (walking to random spots around the map)
- follow (like roam, but walking to random spots near their leader)
- chase (close in on the target, moving to ready_attack when in range)
- attack (play the animation, then change back to ready_attack)
- ready_attack (choose from a list of attacks based on range, then move to attack, or back to chase if not in range)
- emerge (initial state on spawn, plays the spawn animation then moves to idle)
- die (deletes physics nodes, plays death animation and queues deletion)
These states are all attached to basic nodes, with the main script (entity.gd) running their update() functions in process, and enter() and exit() funcitons when moving between. The AI works almost perfectly despite this glaring flaw. And the weird thing is, the enemy AIs don't seem to have the same problem - they work almost flawlessly. But upon introducing the allies, this error has reared its head.
One fix I've found in game is to kill the ally's target, thus resetting their state back to idle. I've hunted through the code to find what might be getting them stuck in chase, to no avail.
Perhaps I should also mention that there is an acquisition timer running throughout idle, follow and roam, that searches for targets and selects one when within its detection radius (an area). This could possibly lead to problems, but I'm at a loss as to how.
This (https://streamable.com/qgz0ds) shows the 'freezing' happening.
And, if you'd like a closer look, here is my repository:
https://github.com/kyzfrintin/Underworld-Wonderland
The relevant sections are under scenes/entities.
A massive thanks to anyone who would like to help!