Behaviour tree check if certains conditions are met then cancel MoveTo

Greetings guys,

Im working on my AI’s behaviour tree and im stuck on a problem.

In my behaviour tree the AI is normally always patrolling, however when GotEnemyInSight/Hear is Set and EnemyDistance is less then 1000 it starts moving towards the player and when close attack him.
Now on the left side im trying to build something for when the player is being chases and runs further away then 1000 the AI will lose the player and start searching. During this search I want him to move to the lastPosition variable, wait there a couple of seconds and then move back IF he doesnt see the player(and lower then the 1000 EnemyDistance) during the search. now I need to put the whole AI Attack part to the left side of my AI Lost part in order to keep track if he finds him… and again and again if I want to let him watch it all the time…

Can anybody tell me how I should change my behaviour tree to make sure that during the search he keeps looking to my AI Attack part if the conditions are met let him chase the player again.

Im sorry if my explaining isnt good, I hope you guys understand if not let me know

Thanks in regards,

Falko

Do you use an ENUM for the different stages your AI can be in? Because normaly you would have an ENUM with, for example,

  • Idle
  • Search
  • Attack
  • Follow
  • etc

And then you would make a switch depending on this enum. For example, if you are in the Follow stage you have some conditions that will put the AI back into Idle, Search or Attack. For example the Distance. So you are in the “Follow” stage and the distance gets less than 10. Now he switches to “Attack”. Inside Attack, you would check if he leaves the 10 units and switch him back to “Follow”. If he gets further away, like 1000 units, you switch him into “Search” and in “Search” you would check if he can see the player again (put him back into Follow, the Attack Part will be triggered by the Follow stage) or if he wasted 10 seconds not finding him and putting him back into the “Idle” stage. Or maybe the “Walk back to your spawn point” stage.

Does this help you? :smiley: