4
\$\begingroup\$

What happens, in a behavior tree, when a priority node chooses another branch over a running branch?

Small example:

Priority 1: Fight
    Sequence:
        -Enemy near?
        -Fight!
Priority 2: Move
    Sequence:
        -Is there a hole?
        -Jump!
    Run 5m!

Now in the first iteration there is no enemy, but a hole, so the action Jump! gets executed. It's a rather lengthy animation so it returns running.

For what should happen in the next iteration I found kind of contradictory statements. According to this answer the priority node always begins at the first priority disregarding if another priority is running. In this article however while the examples follow the same scheme, the explanation also mentions that it's possible to lock the tree in the Running state until it's finished.

If the tree is locked in the Running behavior, the character can't react until he walked all the way to his walking target, so this can't be the right interpretation.

If always the first priority gets checked again, the character can react to enemies while he's running (he stops and fights) - that's the desired behavior. If however he's in the air jumping, he can not just stop and fight, he has to land first, so this time I can't choose priority Fight over Move!

How should I handle those cases? Am I even approaching it the right way?

\$\endgroup\$
2
  • \$\begingroup\$ In your opinion, what should happen in those cases? (Not sarcasm. Deciding what the desired behaviour is is critically important!) \$\endgroup\$ May 11, 2014 at 14:05
  • \$\begingroup\$ @TrevorPowell While he's jumping he shouldn't be able to do anything until he landed again. But while he's running (walking, to eliminate terminological misconceptions) he should always be able to stop and do some other action. One way I thought of would be adding a condition can react? in all other priorities, but that seems to be a clumsy solution. \$\endgroup\$
    – Appleshell
    May 11, 2014 at 14:10

1 Answer 1

5
\$\begingroup\$

The answer you reference assumes tasks that are interruptible. As with nearly all things game development, you can always break the mould to make it work for you. It's certainly possible to make a non-interruptible flag, and set it on the tree when you're running animations and other non-interruptible tasks. When the non-interruptible flag is set, the tree will not restart evaluation from the beginning, it will go straight to the running node.

Also remember that when you evaluate the tree is up to you. You can have a variable wait timer between evaluations or only evaluate when needed. So, for example, you can evaluate only when the character needs a new action to perform, or is available to switch actions. In this case, the tree would not be reevaluated until the animation was complete.

\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .