Behaviour tree AI attacking Player

I am trying to make my zombie AI attack my player character as soon as it is in range. This ‘range’ is determined by a custom box collider on my player character. I am using a behaviour tree to make the AI switch between roaming, chasing and attacking the player. However every time the AI gets close to the player the behaviour tree starts to flicker, the AI does not play the attack animation and often even just walks away from me. I cannot find a decent solution using search engines or the forum so here I am. I am still new to developing so there is a strong possibility it is a small mistake or something that is left out.

Here is an overview of my settings:

Behaviour Tree:

The service where it checks if the zombie is in the collider:

The Zombie character blueprint event graph:

The costum collider that functions as the attack range for the zombie. This is checked to set the blackbord Boolean key:

The chase task. I am posting this to see if it can explain why my zombie runs away (irregular event) after reaching me. This was already happening before the new attack behaviour:

So in short: I am trying to make the AI play his attack animation when he stands in the collider and prevent my AI to walk away from me after reaching the player’s location.

Would the Zombie lose sight of the Pawn during the attack animation?

I suggest, instead of using the collider, to just do some math, get the distance between the zombie and pawn and use that for your check.

Make sure your Play Animation doesn’t have Non Blocking checked.

In your ZombieInRange Service you are trying to cast to MainCharacter. But tue Actor you geht form the Receiver tick is your Zombie. So the cash will always Fail.

I managed to get it o work using math inside of the zombie blueprint. However I would now have to do this for every zombie (ok, maybe I could make a random spawn from that blueprint but it would be a hassle with different animations per spawn but whatever. future problems ;P). However if there is a way to do it within a behaviour blueprint it would be more scalable and more modular. However this will do for now. Thanks for the tip :slight_smile:

You can do it in the behavior BP, just make a new function that sets a BB value based on the proximity, and call that before the decision is made.