Skip to main content

Module behavior

Module behavior 

Source
Expand description

AI Behavior subsystem — Behavior Trees, built-in nodes, and GOAP planner.

§Modules

ModuleContents
treeCore BT engine: BehaviorNode, NodeStatus, Blackboard, BehaviorTree, TreeBuilder, SubtreeRegistry
nodesReady-to-use leaf/decorator constructors: Wait, MoveTo, LookAt, PlayAnimation, CheckDistance, CheckHealth, CheckLineOfSight, SetBlackboard, RandomSelector, WeightedSelector, and more
plannerGOAP planner: WorldState, Action, GoalStack, GoapPlanner, PlanExecutor, GoapAgent, ActionLibrary

§Quick start

use proof_engine::behavior::prelude::*;

// Build a simple patrol-and-attack behavior tree.
let root = TreeBuilder::selector("root")
    .sequence_child("attack_sequence")
        .node(check_in_range("in_range", "agent_pos", "enemy_pos", 5.0))
        .node(fire_at_target("fire", "can_fire", "ammo", "fire_request"))
    .end()
    .node(patrol_set_target(
        "patrol",
        vec![Vec3::ZERO, Vec3::new(10.0, 0.0, 0.0)],
        "wp_idx", "agent_pos", "patrol_target", 0.5,
    ))
    .build();

let mut tree = BehaviorTree::new("enemy_ai", root);
tree.blackboard_mut().set("agent_pos", Vec3::ZERO);

loop {
    let status = tree.tick(0.016);
    // status is Running / Success / Failure
}

Re-exports§

pub use tree::BehaviorNode;
pub use tree::BehaviorTree;
pub use tree::Blackboard;
pub use tree::BlackboardValue;
pub use tree::DecoratorKind;
pub use tree::DecoratorState;
pub use tree::NodeStatus;
pub use tree::ParallelPolicy;
pub use tree::SubtreeRegistry;
pub use tree::TreeBuilder;
pub use tree::cooldown;
pub use tree::invert;
pub use tree::leaf;
pub use tree::parallel;
pub use tree::repeat;
pub use tree::selector;
pub use tree::sequence;
pub use tree::timeout;
pub use nodes::CompareOp;
pub use nodes::check_distance;
pub use nodes::check_health;
pub use nodes::check_health_low;
pub use nodes::check_health_ok;
pub use nodes::check_in_range;
pub use nodes::check_out_of_range;
pub use nodes::check_line_of_sight;
pub use nodes::check_blackboard_bool;
pub use nodes::check_blackboard_float;
pub use nodes::check_blackboard_exists;
pub use nodes::clear_blackboard;
pub use nodes::copy_blackboard;
pub use nodes::cooldown_node;
pub use nodes::debug_log;
pub use nodes::debug_log_blackboard;
pub use nodes::face_direction;
pub use nodes::fail_always;
pub use nodes::fire_at_target;
pub use nodes::flee;
pub use nodes::idle;
pub use nodes::invert_node;
pub use nodes::look_at;
pub use nodes::melee_attack;
pub use nodes::move_to;
pub use nodes::move_to_2d;
pub use nodes::patrol_set_target;
pub use nodes::play_animation;
pub use nodes::random_selector;
pub use nodes::repeat_forever;
pub use nodes::repeat_node;
pub use nodes::set_blackboard;
pub use nodes::succeed_always;
pub use nodes::timeout_node;
pub use nodes::wait;
pub use nodes::weighted_selector;
pub use nodes::blackboard_guard;
pub use planner::Action;
pub use planner::ActionEffects;
pub use planner::ActionLibrary;
pub use planner::ExecutorState;
pub use planner::GoapAgent;
pub use planner::GoapPlanner;
pub use planner::Goal;
pub use planner::GoalStack;
pub use planner::PlanError;
pub use planner::PlanExecutor;
pub use planner::PlanStep;
pub use planner::PlanStepStatus;
pub use planner::Preconditions;
pub use planner::WorldState;

Modules§

nodes
Built-in behavior-tree node library.
planner
Goal-Oriented Action Planning (GOAP).
prelude
Convenience glob import: use proof_engine::behavior::prelude::*;
tree
Behavior Tree core — nodes, blackboard, tick engine, and tree builder.