Behaviour Trees
This week, we’ll be taking a look at behaviour trees in games and how they can be applied.
Behaviour Tree Recap
Recall from the lecture:
-
A behaviour tree is made of nodes, representing tasks
-
Basic actions in the games form the leaf nodes of our tree
-
Notes are combined together using composite tasks
-
Infomation can be shared between nodes using Blackboards
Lets review the most common types of composite types:
Selector |
Run each node in order, if a node succeeds return SUCCESS, else return FAILURE when no nodes are left |
Sequence |
Run each node in order, if a node fails return FAILURE, else return SUCCESS when no nodes are left |
Parallel |
Run nodes at the same time, rules regarding success and failure are determined by the node itself |
Example
Examine the following behaviour tree, and results table.
flowchart TB Selector --> A Selector --> B Selector --> Sequence Sequence --> C Sequence --> D
some rows of the table might not be needed. |
Node | Example 1 | Example 2 | Example 3 |
---|---|---|---|
A |
FAILURE |
FAILURE |
SUCCESS |
B |
SUCCESS |
FAILURE |
SUCCESS |
C |
FAILURE |
SUCCESS |
SUCCESS |
D |
FAILURE |
SUCCESS |
SUCCESS |
Using Behaviour Trees in Unity
There are many behaviour tree assets in Unity. A few years ago, I implemented one for COMP280. This was a 'code only' solution that some of you may remember if you were on the Unity track for COMP280 with me.
The repository is available on
the github server. We’ll be using the same repo, but we’ll use it in slightly different ways. Find the
Assets/Scripts/bt
folder.
The controller script is located in BtController.cs
. Use a tool (such as mermaid JS or similar) to map out
what the behaviours implemented in the Create Tree
method.
Implementing new node types
Reading
Game Engine Spesific
Last updated 2022-12-09