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

Attack with cooldown

Gate the attack branch on a countdown your own component owns, so the graph never keeps a second copy of the timer.

The component that refuses the swing is the component that should be timing the wait.

An enemy should swing, then wait, then swing again. If the graph owns the wait, you have two timers: the one in your combat component that decides whether the hit lands, and the one in the graph that decides whether to try. They drift, and the enemy swings at nothing.

Keep the countdown in the component and read it as a guard at the top of the attack branch.

EnemyBrain.bqbehavior in Horde Survival runs a priority Selector named Attack, Chase, or Hold. The attack Sequence puts its cheap guards first: Has Target, Enemy Alive, then Cooldown Ready. Only once those pass does it run the Distance Squared method and compare the answer in In Contact Radius. Cooldown Ready is a member condition that reads the field ContactAttack.CooldownRemaining and tests it with ≤ against 0. When the countdown is still running the guard fails, the Sequence fails, and the Selector falls through to chase.

A live behavior tree for a horde enemy showing the Attack, Chase, or Hold selector with the chase sequence and its leaves carrying SUCCESS badges.
Figure 1. EnemyBrain in Live. The selector settled on the chase branch for this tick, which is what happens while the attack branch’s guards say no.

The countdown already lives in a component, so the graph reads it as a fact instead of keeping a second clock.

  • Selector with attack above chase above hold.
  • Sequence for the attack branch, so the first failing guard ends it.
  • Member condition reading the field ContactAttack.CooldownRemaining, and again reading Health.Current for the alive check.
  • Method for the static distance calculation the range check compares against.

Two rules make this shape work in your own game. Put the countdown where the ability already lives, so the component that refuses the swing is the component that measures the wait. Then make the guard the first child of the attack branch, so a swing that is impossible costs one comparison.

Full-size image