User Tools

Site Tools


behavior-trees

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
behavior-trees [2020/05/22 12:36]
maxime
behavior-trees [2020/07/17 15:11] (current)
maxime
Line 1: Line 1:
 ====== Behavior Trees ====== ====== Behavior Trees ======
  
-You can find an example of behavior tree and behavior tree node creation in the ''​Example 02'' ​mod, in the file ''​scripts/​behavior_tree.lua''​.+You can find an example of behavior tree and behavior tree node creation in the following mods: 
 +  * ''​Example 01''​ (file ''​wooden_keep_guard_locator.lua''​) 
 +  * ''​Example 02'' ​(file ''​scripts/​behavior_tree.lua''​).
  
 ===== Register new behavior trees ===== ===== Register new behavior trees =====
  
-You can now create custom behavior tree assets with ''​foundation.registerBehaviorTree''​.+You can now create custom behavior tree assets with ''​[[:​mod-management-functions#​registerBehaviorTree|mod:​registerBehaviorTree]]''​.
  
 A behavior tree is defined as a table containing an ID (''​Id''​),​ a list of variable (''​VariableList''​) and an execution tree (''​Root''​). A behavior tree is defined as a table containing an ID (''​Id''​),​ a list of variable (''​VariableList''​) and an execution tree (''​Root''​).
Line 11: Line 13:
 ==== VariableList ==== ==== VariableList ====
  
-Each variable in the list must contain at list a unique ''​Name'',​ and a ''​DataType''​. The ''​DataType''​ must be a type inheriting ''​[[preview:api:​behavior_tree_data|BEHAVIOR_TREE_DATA]]''​.+Each variable in the list must contain at list a unique ''​Name'',​ and a ''​DataType''​. The ''​DataType''​ must be a type inheriting ''​[[api:​behavior_tree_data|BEHAVIOR_TREE_DATA]]''​.
  
 You can also specify if a variable is public (''​IsPublic''​),​ thus specifying if this variable must be filled by the outer tree when this tree is used as a sub-tree node. You can also specify if a variable is public (''​IsPublic''​),​ thus specifying if this variable must be filled by the outer tree when this tree is used as a sub-tree node.
Line 27: Line 29:
 Leaf nodes (''​NODE_LEAF''​) cannot have children. Some are defined in the core game, but you can also [[behavior-trees#​custom_behavior_tree_nodes|define your own]]. Leaf nodes (''​NODE_LEAF''​) cannot have children. Some are defined in the core game, but you can also [[behavior-trees#​custom_behavior_tree_nodes|define your own]].
  
-When defining a node in a new behavior tree, you have to specify at least its unique name (''​Name''​),​ and its type (''​Type''​) inheriting from ''​[[preview:api:​node|NODE]]''​. If the node has public variables, you have to link by name each of the node's variables to the tree variables.+When defining a node in a new behavior tree, you have to specify at least its unique name (''​Name''​),​ and its type (''​Type''​) inheriting from ''​[[api:​node|NODE]]''​. If the node has public variables, you have to link by name each of the node's variables to the tree variables.
  
 Finally, if the node is a branch node, you have to add the list of children (''​Children''​). Finally, if the node is a branch node, you have to add the list of children (''​Children''​).
Line 39: Line 41:
 ==== VariableList ==== ==== VariableList ====
  
-The list of variables is a simple key-value pair list with the variables name as key, and its type (inheriting from ''​[[preview:api:​behavior_tree_data|BEHAVIOR_TREE_DATA]]''​) as value. Each of those variables are input by the tree using the node.+The list of variables is a simple key-value pair list with the variables name as key, and its type (inheriting from ''​[[api:​behavior_tree_data|BEHAVIOR_TREE_DATA]]''​) as value. Each of those variables are input by the tree using the node.
  
 ==== Functions ==== ==== Functions ====
  
-A leaf node has three basic functions: ''​Init'',​ ''​Update'',​ and ''​Finish''​. The ''​Update''​ function takes the level (''​[[preview:api:​level|LEVEL]]''​) and the tree instance (''​[[preview:api:​behavior_tree_instance|BEHAVIOR_TREE_INSTANCE]]''​) as parameter, and returns a ''​[[preview:api:​behavior_tree_node_result|BEHAVIOR_TREE_NODE_RESULT]]''​.+A leaf node has three basic functions: ''​Init'',​ ''​Update'',​ and ''​Finish''​. The ''​Update''​ function takes the level (''​[[api:​level|LEVEL]]''​) and the tree instance (''​[[api:​behavior_tree_instance|BEHAVIOR_TREE_INSTANCE]]''​) as parameter, and returns a ''​[[api:​behavior_tree_node_result|BEHAVIOR_TREE_NODE_RESULT]]''​.
  
-When a node is executed, the ''​Init''​ function is called first. Then, the ''​Update''​ function is called until it doesn'​t return ''​[[preview:api:​behavior_tree_node_result|BEHAVIOR_TREE_NODE_RESULT.PROCESSING]]''​. Finally, the ''​Finish''​ function is called.+When a node is executed, the ''​Init''​ function is called first. Then, the ''​Update''​ function is called until it doesn'​t return ''​[[api:​behavior_tree_node_result|BEHAVIOR_TREE_NODE_RESULT.PROCESSING]]''​. Finally, the ''​Finish''​ function is called.
  
 You can access all of the node's variables in those functions with ''​self''​. You can access all of the node's variables in those functions with ''​self''​.
behavior-trees.1590165382.txt.gz · Last modified: 2020/05/22 12:36 by maxime