AI Tree Behavior Help Please

I am currently using the AI tutorial posted on Unreal Engine’s documentation page to create an AI system that has the AI attack me when it sees me. What I can’t seem to figure out is how to get it to stop at a set distance away from the player character, and start shooting. I have it currently where I have it check the distance between the player and the AI, and if its true, it will fire the attack function which I have set up a trace line and health system. I implement this and nothing happens except the AI runs all the way to the player. How would I go about fixing this?

Thank you.

alt text

I think the problem with the AI not stopping to shoot the player is because the Task “RapidMoveTo” is not being aborted, so the task will only end when its near the player.

Here is my try on this problem. The Behaviour Tree looks like:


Note how the “CloseEnough” decorator can “abort self”, and I also increase the distance. If the AI is far away from the player, the “CloseEnough” will return True (the name is confusing, but I’m following the tutorial). When the AI gets closer to the player, the “CloseEnough” will become False, and will abort the task “RapidMoveTo”. The top selector then will execute the next task, that is “Shoot”.

Below is my attempt at creating a “RapidMoveTo” task that can be aborted:


That’s probably not the most elegant way to handle it but it worked on my little test, and you may improve it from here.

I’m still trying to get it, but its not working for some reason. I’m going to try and rebuild it again. Ill keep trying and let you know what happens.

Make sure the capsule in the AI_Character blueprint (assuming you have it all the same as the tutorial) has the same half-height as the “TopDownCharacter”. With a height too different then the AI may never reach its “target” and it will get stuck in the “Move To” task.