0
Answered

How to Organize Behavior Tree With Parallel Actions for Each Task?

Cr4shBarcode 8 months ago in Behavior updated by Marti (Lead Developer) 8 months ago 3

I'm using the Behavior Module and I've been following the online tutorial. My enemy has two types of banter set to run parallel to his actions: banter running parallel to his patrol action, and banter running parallel to when he is following the player. I don't know enough about behavior trees to be sure, but do I need to change the selector node into a sequence node in order to have different parallel actions for both the follow and the patrol actions?

Unity version:
Game Creator version:

Answer

Answer
Answered

Depends really. If you use a Selector:

It will execute the follow Player as long as the enemy sees it. Otherwise it will enter a patrol state. Selector nodes work like an "IF" condition: "If the conditions on the left are true, execute the left node. Otherwise execute the right node".

If you use a Sequence node it will first execute the left node actions. Once these are finished, it will jump to executing the right node actions. A Sequence would be roughly translated to: "After you finish left node, execute the next one".

Selectors are more suitable for your case. On the other hand, Sequence nodes are usually meant to be used for actions that are executed one after another. For example; when you're patrolling, you may want to make the character stop near a table, grab a cup of coffee, play the animation of drinking it and continue with the patrol. This would be a sequence: Move to table, play gesture "grab coffee", play gesture "drink coffee", continue patrol.

Answer
Answered

Depends really. If you use a Selector:

It will execute the follow Player as long as the enemy sees it. Otherwise it will enter a patrol state. Selector nodes work like an "IF" condition: "If the conditions on the left are true, execute the left node. Otherwise execute the right node".

If you use a Sequence node it will first execute the left node actions. Once these are finished, it will jump to executing the right node actions. A Sequence would be roughly translated to: "After you finish left node, execute the next one".

Selectors are more suitable for your case. On the other hand, Sequence nodes are usually meant to be used for actions that are executed one after another. For example; when you're patrolling, you may want to make the character stop near a table, grab a cup of coffee, play the animation of drinking it and continue with the patrol. This would be a sequence: Move to table, play gesture "grab coffee", play gesture "drink coffee", continue patrol.

How would I make sure that the "follow" and "patrol" states have separate parallel actions? Right now, the "Patrol Banter" plays regardless of if the AI is following or patrolling.

Check out the video tutorial about Hide & Seek: The enemy, as long as it's not seeing the player, it wanders around following a patrol route. As soon as it sees the Player, it abandons its patrol and starts chasing the Player.

This is done using a Selector, which can be read as:

  • Left Node:
    • Conditions: If Enemy can see Player
    • Actions: Follow Player
  • Right Node:
    • Actions: Patrol

Here's the video tutorial: