A strong implementation of a BehaviorTree system in pure Lua, useful for implementing Artificial Intelligence in many domains (robotic, games, etc...), and with support of XML language.
You just need to clone or download this project as zip to get the source files. Once you have these sources somewhere in your project, import the /LuaBehaviorTree/src/BehaviorTree.lua
file, or just the /LuaBehaviorTree/src
directory (only if you have ?/init.lua
in your search path.) where you want to use the library.
local BehaviorTree = require "LuaBehaviorTree.src.BehaviorTree";
TODO
This BehaviorTree implementation comes with a predefined set of nodes, which are largely sufficient to build any custom nodes.
Node
: The base implementation of every nodes.Action
: The base implementation of every leaf nodes (actions).BranchNode
: The base implementation of every branch nodes.DecoratorNode
: The base implementation of every decorator nodes.
EmitEvent
: A node used to emit a specific event giving its name. Returnssuccess
when the event is emitted, andfailure
otherwise.Return
: A node used to return a value (success
,failure
, orrunning
) directly in the behavior tree.
Fallback
: A node which executes sequentially all of its children until one of then return asuccess
state. Returnssuccess
if one of its children returnssuccess
, returnsfailure
if all children has returnedfailure
, returnsrunning
if the current executing child returnsrunning
.Random
: A node which pick randomly only one of its children and execute it. Returns the same result as the executing child.ReactiveFallback
: A node which executes each child nodes sequentially until one node returnssuccess
, then, itself returnssuccess
. If every child nodes returnsfailure
, theReactiveFallback
node returnsfailure
. If a node returnsrunning
, the whole sequence is restarted to the first child.ReactiveSequence
: A node which executes each child nodes sequentially until one node returnsfailure
, or all nodes returnssuccess
. If every child nodes returnssuccess
, theReactiveSequence
node returnssuccess
too, otherwisefailure
. If a node returnsrunning
, the whole sequence is restarted to the first child.Sequence
: A node which executes each child nodes sequentially until one node returnsfailure
, or all nodes returnssuccess
. If every child nodes returnssuccess
, theSequence
node returnssuccess
too, otherwise returnsfailure
.SequenceStar
: ASequence
node used when you don't want to tick children again that already returnedsuccess
.
ForceFailureNode
: A node which will always returnfailure
whatever its child node returns.ForceSuccessNode
: A node which will always returnsuccess
whatever its child node returns.InvertorNode
: A node which will returnsuccess
when its child returnsfailure
, andfailure
when its child returnsuccess
. This node will returnrunning
if its child returnsrunning
.RepeatNode
: A node which will repeat the execution of its child for a given number of times. Returnssuccess
when it reach the given amount of iterations, andrunning
if its child returnsrunning
during an iteration.RepeatUntilFailureNode
: A node which will repeat for a maximum number of times the execution of its child until this last one returnsfailure
. If the child node returnfailure
before the maximum iteration count is reached, theRepeatUntilFailureNode
returnssuccess
, otherwise returnsfailure
.RepeatUntilSuccessNode
: A node which will repeat for a maximum number of times the execution of its child until this last one returnssuccess
. If the child node returnsuccess
before the maximum iteration count is reached, theRepeatUntilSuccessNode
returnssuccess
, otherwise returnsfailure
.
StateMachine
: TheStateMachine
node is a composite node allowed to have one or more children. The children of aStateMachine
node must all beState
nodes. Only oneState
node is allowed to run at a time and the first one defined (the first child node) is the first one to run. The current status of aStateMachine
node is the same as the child that is currently selected to run.State
: TheState
node is the basic block of aStateMachine
node. EachState
node must have aBehaviorTree
node and may also have aTransitions
block. AState
node runs the content of itsBehaviorTree
node and can transit to another state (or itself) as specified in theTransitions
block. If aState
node transits into itself while running, it will first be terminated, re-initialized, and then updated again.Transition
: TheTransition
node is used in theState
node to define the set of transitions from/to other states in the same parentStateMachine
node.
BehaviorTree
: The topmost node of each behavior tree created using this library. Can only have one root node, and may content a set of properties, events, and subtrees.Events
(XML only): A node having a set ofEvent
nodes.Event
(XML only): A node used to create a behavior tree event.Properties
(XML only): A node having a set ofProperty
nodes.Property
(XML only): A node used to create a behavior tree property.Root
(XML only): A node used to define the root node of the behavior tree. Can only have one child.SubTrees
(XML only): A node having a set ofSubTree
nodes.SubTree
: A node used to create a behavior tree subtree. Since this node can be used outside of an XML context, it's mostly useful (and also makes sense) in XML to create a composite node using other nodes.