Expand description
Built-in behavior-tree node library.
Every function in this module returns a BehaviorNode::Leaf (or a small
composite that acts like a logical leaf) that encapsulates one well-defined
game-AI action or condition. They are designed to be composed with
crate::behavior::tree::TreeBuilder.
§Node catalogue
Actions (mutate world state / run over time)
wait— pause for a fixed durationmove_to— move agent toward a target positionlook_at— rotate agent to face a targetplay_animation— trigger and wait for an animation clipset_blackboard— write a value onto the blackboard
Conditions (instant pass/fail checks)
check_distance— is agent within/outside a range?check_health— compare health against a thresholdcheck_line_of_sight— can the agent see a target?check_blackboard_bool— read a bool flagcheck_blackboard_float— compare a float value
Decorator wrappers (higher-order node constructors)
invert_node— flip Success↔Failurerepeat_node— run child N timestimeout_node— fail child if it takes too long
Composite helpers
random_selector— shuffle children then selectweighted_selector— pick child by probability weight
Enums§
- Compare
Op - Condition: compare a health value on the blackboard against a threshold.
Functions§
- blackboard_
guard - Only tick child when a blackboard bool key equals
expected. - check_
blackboard_ bool - Condition: return Success if
keyholds a truthy bool. - check_
blackboard_ exists - Condition: succeed if key is present in the blackboard.
- check_
blackboard_ float - Condition: compare a float blackboard value.
- check_
distance - Condition: is the distance between two Vec3 positions within
[min, max]? - check_
health - Condition:
health_key OP threshold→ Success / Failure. - check_
health_ low - Shorthand: succeed if health <
threshold(agent is wounded). - check_
health_ ok - Shorthand: succeed if health >=
threshold(agent is healthy). - check_
in_ range - Condition: is the distance within
range(i.e.0 <= dist <= range)? - check_
line_ of_ sight - Condition: can agent see target?
- check_
out_ of_ range - Condition: is the distance strictly outside
range? - clear_
blackboard - Remove a key from the blackboard and succeed.
- cooldown_
node - Only tick
childif at leastcooldown_secshave elapsed since last tick. - copy_
blackboard - Copy a blackboard value from one key to another and succeed.
- debug_
log - A leaf that logs a message and always succeeds. Useful for tracing tree execution during development.
- debug_
log_ blackboard - A leaf that logs the current value of a blackboard key and succeeds.
- face_
direction - Instantly snap the agent’s yaw to face a target position.
- fail_
always - A leaf that always fails immediately.
- fire_
at_ target - Action: attempt to fire a projectile at a target.
- flee
- Move the agent away from a threat position stored on the blackboard.
- idle
- Always-running idle node. Returns Running indefinitely.
- invert_
node - Wrap
childin an Invert decorator: Success↔Failure, Running unchanged. - look_at
- Smoothly rotate the agent’s yaw toward a target.
- melee_
attack - Action: perform a melee attack if the target is within
melee_range. - move_to
- Move an agent toward a 3-D target stored on the blackboard.
- move_
to_ 2d - Variant that reads the target from a
Vec2position and moves in 2-D. - patrol_
set_ target - Move through a fixed list of waypoints in a loop.
- play_
animation - Trigger a named animation clip and block until it finishes.
- random_
selector - A Selector that shuffles its children randomly on each activation, then tries them in the shuffled order. Because the shuffle is computed per-activation (inside the tick closure), the node re-shuffles every time the selector restarts.
- repeat_
forever - Repeat
childforever (always returns Running). - repeat_
node - Repeat
childexactlycounttimes; succeed only if all iterations succeed. - set_
blackboard - Instantly write a value onto the blackboard and succeed.
- succeed_
always - A leaf that always succeeds immediately.
- timeout_
node - Return Failure if
childis still Running aftertimeout_secsseconds. - wait
- Pause execution for
duration_secsseconds, then succeed. - weighted_
selector - A Selector that picks exactly one child based on probability weights and ticks only that child. Each activation samples a fresh child.