-
Notifications
You must be signed in to change notification settings - Fork 18
Quick Start
This page serves as a super quick summary of the main points of the Behavior system. The details of each part are detailed on their respective pages (check out the menu on the right).
For this tutorial, we'll assume you have an entity/creature you want to bring to life. If you don't, check out this tutorial to learn how to create one.
Behavior trees are the structures used to describe the behavior of an entity within the game. A behavior is a pre-defined set of actions performed by an entity, triggered by specific conditions or events. Behaviors can be related to movement (animals wandering in an open field) or more complex actions (searching for water sources to fulfill a specific need).
In Terasology, a behavior tree is described in a JSON-like file, which contains pre-defined elements (nodes) and actions associated with these nodes. These files (.behavior
) are located in the assets/behaviors
folder of each module. Behavior trees are composed of objects implementing the TreeNode
interface. To learn more about the structure of behavior trees, please see this link. To see how a behavior tree can respond to events and changes in the entity, see here. If you want to create your own Behavior (.behavior
) file, you can learn how to do it here.
To possess a behavior, an entity must have a Behavior
component referring to an existing behavior tree. To specify the behavior tree your entity will use, go into its .prefab
file, and find (or create) the Behavior
entry in the JSON.
The correct format is:
"Behavior" : {
"tree" : "<module>:<behavior>"
}
You can use any pre-made behavior existing in another module. If you use the stray
behavior from the Behaviors module, for example, your .prefab
behavior entry will be:
"Behavior" : {
"tree" : "Behaviors:stray"
}
If you create your own .behavior
file, you don't need to reference the module in the .prefab
file - e.g. if you created a custom run.behavior
file, your prefab should look like this:
"Behavior" : {
"tree" : "run"
}
A curated list of pre-made behaviors can be found here.
Behaviors can also be used by groups of entities. Similarly to behaviors, a group is described by JSON-like files (.group
) are located in the assets/groups
folder of each module. Groups can be used in situations where the same behavior must be assigned to multiple entities at a time. For more details on groups, please see this link.
Behavior trees can also be created or edited through the use of the Behavior GUI editor. The GUI editor is currently unstable, but its latest version can be accessed in-game through the F5
key. At this moment, we recommend that you edit your .behavior
files directly.
If you want to learn how to build your own behavior, please check this link. Also - if you want to start by learning how you can reuse existing code by modifying existing behaviors and adapting it to your scenario - there's a case study about it available here.