Ok, found some time to explain the video a bit.
What you see is me playing around with minions, mazes and the behavior tree implementation. The four used tools (all have scissor icon) are:
- Red spawner: Just spawns the next red model (pawn, fool, king, knight, queen, rook).
- Assign Walk to job: Use selection tool to assign the walk to block job to any solid block in the selection.
- Build wall: Fills the selection with dirt blocks. Any other block will be replaced.
- Build maze: Builds a maze in the selection. May be even higher than 3 levels to get crazy multilevel mazes.
Each spawned minion has a "Behavior" component assigned. This will make the minion to behave in the world described using a behavior tree. The tree itself is displayed in the BTEditor. This editor not only shows the currently assigned tree (and its current execution state) but also allows you to fully edit the tree (add nodes, connect, disconnect).
The main missing part before having a somewhat useful editor is the property editor (each node may have different properties you can edit), some ui improvements and correctly storing/loading behavior trees to filesystem and assign them to entities.
The tree used in the video is basically the one I posted earlier. You can see the tree in the overlay. Its just straight forward (as I am writing this text, I can see some bugs in the tree
), a little moving around and playing an animation. The cool part is, how easy the pathfinding and the (currently just sketched) job system integrates into the tree.
For pathfinding, there is a node FindPathTo
which will trigger the pathfinder (Notice: the pathfinding runs in a background thread). As long as the path is searched, this node will return RUNNING
. Once a path is found (or not found), the node returns SUCCESS
and the next task in the sequence starts.
In the example this is MovingAlongPath
which will do exactly what its name says. Notice, this node uses another node (MoveTo
) to operate.
The job system is implemented using nodes too. The FindJob
node will find an available job (this is random by now), SetTargetToJob
will assign minions move target to a position, so that the job can be fulfilled. Finally FinishJob
will try to run the job (if the minion can reach the jobs target position) and remove it from the job board.
So far, I am really happy with the result.
- Nodes are not allowed to communicate to each other. The only way to change state informations between nodes (for example, FindPathTo needs to tell about the path to the MoveAlongPath node) is using the minion. For that, I dynamically add or remove components with the properties required to exchange. As an alternative, I may use a blackboard where each node can write to and read from. Each minion has its own blackboard. This way its also possible, to make nodes write/read from some kind of variables, so multiple calls to same node would be possible.
- Introduce conditions as special nodes. Those nodes cannot modify anything (not even the blackboard) - they just checking the world for something and return either SUCCESS or FAILURE (no RUNNING). They are called every tick (only active nodes are called per tick) before any other node is called. Other names may be sensor or guard, since they help aborting deep runs into the BT very early.
- Nodes, nodes & nodes. We need many of 'em. And we need good ones.
- What to do with the editor? Currently its a basic swing application which gets started from inside a component system. This is not possible for any mod and should be changed soon. Many ways are possible: Enhance TeraEd to include it somehow. Needs massive refactorings to TeraEd. Fully extract the editor into its own app and using network to comunicate to a running Terasology. My favorite: Use NUI to implement the editor
- Behavior files: Its possible to store and load behavior trees to/from json. Actually its not one tree, but two trees. The first is the core tree, which can be executed. The second is another tree with additional information for the editor only (position, size, ...). Some of this trees may be included in mods (as an asset). Other may be saved to disk by the user.
- more to come