AggrevateNearbyEnemies() method aggravates that same enemy who shouts

Apparently, this method aims to aggravate other enemies nearby an enemy ends up aggravate the very same enemy who run it. And because the method is called by AttackBehavior() in Update() then the enemy keep being aggravated in an infinity loop and never stop chasing player far beyond chaseDistance and aggroCooldownTime
I include a Debug.Log in AggrevateNearbyEnemies() and test on one of them, and yeah he was aggravated by this method and never escape the AttackBehavior state.

Not sure how to fix this yet :frowning:

Solved, I just added another if statement before calling ai.Aggrevate() to exclude itself, if the list contain itself, foreach loop will continue without calling. Look like this

foreach (RaycastHit hit in hits)
            {
                AIController ai = hit.collider.GetComponent<AIController>();
                if (ai == null) continue;  
                if (ai == this) continue; // AI not aggrevating itself                          

                ai.Aggrevate();                
                Debug.Log("Aggrevate an AI");                

            }

I also encounter another bug that if enemies group together in a small space, they would aggravate each other and never escape AttackBehavior. Renan_Pinho here has resolved it

1 Like

Well done sorting this. It’s a known issue, and there are a few threads here and there with the subject.
You can also try filtering out aggro based on whether the character can actually see the player…
The basic idea is that an enemy only calls out aggro if they themselves can physically see the player (or if they were just hit by an arrow/spell), for that frame only.
This will still have the effect of aggravating the enemies, but it shouldn’t provide a feedback loop.

I also like to keep a Vector3 last known position, so if the enemy loses sight of the player, he’ll run to the last spot he saw the player and dwell. Once the aggro timer runs out, he would still go back to whatever he was doing.

2 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms