State as an action in a behavior tree

From what I understand on behavior trees, each behavior should be a short-term goal-oriented action that can be completed in several iterations.

So, for example, below is an image of a behavior tree:

enter image description here

Now suppose Drive To Enemy behavior takes more than a few iterations in a tree. Therefore, Drive To Enemy is called on each pass, because it is now operational.

The problem is what I want to call Evade Enemy if the Enemy is nearby. And given that Drive To Enemy is always called, I never get the opportunity to call Evade Enemy (perhaps Avoid Enemy should be called).

  • Do I have to pass the Tree EACH pass no matter what action is currently being performed?
  • Am I doing it right?
  • What is the correct way to handle this behavior?
+4
source share
1 answer

I would say that going through all the vertices to the top will be your last resort every time if the idea below does not work for you:

As Alex Champandard says on his aigamedev.com website, the basic idea is that while you are in the โ€œDrive To Enemyโ€ behavior, you include some way to perform some additional checks to make sure that the behavior continues .

The Alex method should use parallel composite : a type of node behavior tree that simultaneously runs all its children.

It will look like this:

  • MainSelector:
    • Enemy Dodge
      • Find the enemy
      • Drive in the opposite direction
    • Parallel
      • Is the enemy close?
      • Enemy Chase
        • Find the way to the enemy
        • Drive to the enemy
        • Fire weapon
    • Chase flag
      • Find the flag
      • Find the way
      • Flag drive

Will the parallel node continue to evaluate "Enemy nearby"? node (at a reasonable pace), even when the execution is deep inside the "Chase Enemy" subtree. The moment "Near the enemy?" returns a failure, the parallel immediately returns a failure and skips the completion of the "Chase Enemy" behavior. Thus, the next assessment of your tree will achieve the "Evasion of the enemy" behavior.

"Near the enemy?" the condition then acts as a kind of approval check or early check. Essentially, it's like an event-driven function where your tree can respond to events, even if it hasn't completed its iteration yet.

How I developed my system, although I do not use parallel behavior (I can not multithreadedly work with the third-party game engine that I use). Instead, I have a composite that does almost the same thing, only it evaluates the checks between each round for their children. As a kind of alternation, jumping back and forth from normal execution to evaluating checks. Only if the validation fails, do we return to the top.

+4
source

All Articles