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.
source share