Behavior Tree - Back & Forth on a sidescroller

Hello guys,

I’m trying to make a “patrolling” for my AI by using a Behavior Tree. There’s plenty of tutorials for having your NPC goes to a random location by “Get Random Point…”
But I can’t find a way to tell to my AI : Go here(1), then here(2), then go back to here (1) etc…

I’m working on a Sidescroller in 2.5d so my AI is on a Constraint Plane and I’m actually trying to make it simply goes back and forth.

Why a Behavior tree ? Because it’s easier I think ? Plus, when an enemy see the player, it starts to chase him in a certain range (His sight)
And I don’t know how to tell to the AI to go back to his routine if the player leave his sight range so…

If you guys could give me a hand, i’d appreciate that a lot.

Thank you guys !

  1. You need Waypoint “system”. Add four vector variables to your Patrol_AI_Character. Two of them expose as 3D widgets. Then add logic to Patrol_AI_Character ConstructionScript. You need vector offset to get world location of each Waypoint.

Now you need Blackboard
1. Waypoint_00_Vkey
2. Waypoint_01_Vkey -patrol points
3. IsPlayerDetected_Bkey - bool variable answers Is player close enough?
4. Target_ObjKey - this ActorKey is Player reference

  1. Now build BehaviorTree:

  1. You need Service to update IsPlayerDetected_Bkey. Patrol_BT_Service. This service check does distance between Patrol_AI_Character and player less then DetectionDistance and set IsPlayerDetected_Bkey. Simple - only distance, no trace. Then set target reference.

  1. Now set default Blackboard in your AI_Controller. Patrol_AI_CON.:
    Set Blackboard-> Set Initial values of Waypoints location → Run BehaviorTree

This is it. Change DetectionDistance inside Patrol_BT_Service or move Waypoints. Set Patrol_AI_Character maxWalkSpeed less than Player WalkSpeed. Hi!

Wow. Thanks for that. It looks really great…

Sadly, I can’t make it works and I can’t figure out why. I followed all these steps you gave me but my AICharacter doesn’t want to move.

Here are my blueprints… I checked multiple times but didn’t see any error…

Could you give me some help here ? Do I have something to add, did I miss something ?

Otherwise, thanks a lot for your help.

I think you can combine this with knowledge from BehaviorTree and EQS official documentation tutorials.

You real MVP.

Thank you for everything TVinforest. There was some flaws, now it works pretty well.

This method is really nice and clear.