Behaviour Trees - Lyinginbedmon/TricksyFoxes GitHub Wiki
Behaviours trees are a popular AI architecture that has been utilised in numerous video games over the years. In Tricksy Foxes, they are the origin of the "Tricksy" aspect which the mod is built around, allowing enlightened mobs to be taught to perform various tasks as needed.
An example behaviour tree, viewed through a prescient candle
Trees are built from a variety of interconnected nodes. Each node performs a specific function, and taken as a whole they provide a flexible and dynamic AI system. The nodes available, to enlightened mobs, and their associated variants, are explained below. Many nodes additionally accept input values and output targets derived from one or more whiteboards, depending on their exact variant, allowing them to alter their function according to context.
The Basics
Nodes are objects of a certain type and subtype that perform a calculation and return a result, with the type defining the greater function of the node and the subtype determining its more precise operation. The result can be success, failure, or "running" (if a calculation needs more time to finish). Depending on their subtype, nodes may have one or more input variables. Some of these are mandatory and the node will fail if they are not provided, but others are optional (indicated in italic) and can be specified but otherwise default to certain predefined values.
The calculation can be based on the result of a descendant node (as with most decorator and control flow nodes), on a specific circumstantial condition (as with all condition nodes), or on an ingame action (as with leaf nodes). Nodes can only have one parent node and may have many child nodes (with the exception of condition and leaf nodes, which cannot).
Every tick, the behaviour tree updates by following the path laid out through the nodes based on their result. If a node returns failure, the path generally continues until another node returns a different result, but this is subject to how the tree is structured.
Some nodes may have a cooldown time. This means that once it has returned an end state (either failure or success) it cannot be used by the same mob anywhere else in the their behaviour tree until that time has elapsed. This is usually done by nodes that are computationally-expensive or especially powerful (such as most special leaf nodes).
The Editor
As behaviour trees are complex objects consisting of discrete individual nodes each with their own functions and input variables, version 2.0 introduces a thorough dedicated editor system for manipulating them.