Skip to content
Bit Quirky Behavior Trees and
State Machines

Search documentation

All topics and APIs

Close returns focus to Search.

What are you looking for?

Try a common topic or enter a complete API identifier.

Browse the reference instead

Esc closes · Tab reaches results · Enter opens the focused link

v0.6.0
Menu

Patrol and chase

Put the urgent branch above the routine one under a Selector so chasing always beats patrolling, without a single flag.

Chasing has to beat patrolling whenever the guard gets the choice, and one Selector is the whole mechanism.

A guard walks a route. When it sees the player it must chase, and when sight breaks it must go back to walking that same route. Written with flags, “am I chasing” ends up read by movement, by animation, and by the alarm, and one of them reads it a frame late.

One Selector with the branches in priority order: the most urgent first, the routine job last. The Selector tries each child in turn and stops at the first one that runs or succeeds, so patrol is reached only when nothing above it wanted the tick.

A Selector node labeled choose the next job with three children: a Sequence called chase player, a Random Selector called choose a search route, and a Parallel called keep watch.
Figure 1. A priority Selector in the Platformer gallery graph DocumentationFlowControls.bqbehavior. Chase sits first, the search routine second, the standing job last.

Dungeon Heist runs the production version. Guard2.bqbehavior has a single root Selector whose children are, in order: reset, catch, chase, capture stimulus, investigate, search, return to route, and patrol. Patrol is the last child, which is exactly why a guard that can see you never walks its route.

Reach for this the moment one behavior has to outrank another: a guard that must break off its route, a companion that must stop fetching when you take damage, a turret that must abandon its sweep for a real target. Put the branch you would interrupt for at the top, put the thing it is allowed to interrupt at the bottom, and let the Selector be the priority document. Each branch keeps its own guard, so no branch has to know the others exist.

When the top branch has to win while a lower one is still mid-action, set the Selector’s Reactive abort > Abort to Lower priority. Without it the running branch keeps the tick until it finishes.

  • Selector as the priority list.
  • Sequence inside each branch, so a branch fails fast when its first guard says no.
  • Member condition as each branch’s guard. Guard2 uses clear player sight and chase running at the top of its catch branch.
  • Repeat inside the chase branch, so pursuit keeps running until sight breaks.
Full-size image