Thank you for such an explained answer!
After thinking and trying ideas you wrote I almost got the solution.
At the moment my AI consists of 3 main states:
- Chase the main level target (i.e. the closest crystal that the player has to defend)
- Chase a target that attacks it or a player (not a tower) that’s in AI’s vision sphere
- Attack if there’s something in a narrow trigger box that’s in front of the AI.
The behavior tree looks the following:
The sight sphere and attack trigger look the following:

I’ve created a Navigation Area that’s used by towers. The area only modifies the default cost by a value that will make the AI prefer going around the tower, but not going all the way around if the whole path is blocked. The value that I’ve found good enough is 10.
However, there’s a little problem with that. If the acceptance radius on MoveTo is low enough, then AI probably won’t face sharply the tower, but go around it because of the navmesh generation. Here’s a small video example: 2022 12 02 19 24 24 - YouTube. The solution is to increase the acceptance radius, but not too much; the attack trigger has to be long enough to reach the target.
After that I’ve used the created navigation area on the towers collision component, and checked Dynamic Obstacle and Can Ever Affect Navigation check boxes.
The result I’ve tested on a simple case that consists of a simple corridor with a barricade and a tower. If there’s enough space to go around the barricade, the AI will do so, if there isn’t however, it will not. And yes, it works on the example from the original post as well.
Attacking / agro part wise: by default the AI follows a path that leads to its final objective – crystal. However, it can be distracted by a tower or a player.
A tower can distract an AI only by attacking it. After the AI has been hit, the Target object on blackboard will be set, making the AI chase the tower. As soon as the AI gets close enough to the tower, the latter will be inside the narrow attack trigger, resulting the Attack bool on blackboard to be true, and so the AI will attack the thing that’s in front of him.
With this approach the barricades are defeated as well. If an AI is targeting a tower that’s behind some barricades, and they’re on the most efficient path for the AI, then it will walk into them, resulting the attack trigger to do its job – make the AI attack something that’s on the way, even if it’s not the object that the AI is thinking of.
A player, however, have more options to distract the AI:
- he can just enter into their sight sphere, and if there’s no active target (except the main one – the crystal), then it’ll become one unless not gone too far (outside the sphere)
- attack the AI while outside the sight sphere; if the active target (the crystal or a tower) is farthest than the player, then target the player, otherwise ignore him.
There are some problems with this approach however.
If the AI have started attacking a barricade, it won’t stop until dead or destroying the barricade; if someone else destroys a barricade (or something else that may prevent the path) that’s nearby, the AI will keep attacking regardless.
Nevertheless, I think that some of the problems with this approach may be ignored or fixed depending on the developers will, because there’re many things to consider which may easily be different for everyone.
Hopefully my final answer will help someone else struggling with similar problem. ![]()
