A little while ago I tried to understand what Behaviour Trees are about, as in a couple of games I’m developing I have sets of NPCs that I have to manage and I would like to somehow decouple their behaviour from the main game flow. Here you can find a good explanation of behaviour trees.
1. Distinguish between the tree description and the instance tree being run: you need a concrete instance as you need to be independent of “tick” speed and need to be able for each instance to find what is the current node.
2. You need to handle single node completion asynchronously e.g. if you have a “chase” node, this may take a long time to resolve.
Now we have our implementation, its very simple code and can be useful in a wide variety of game development situations – surely its not a complete solution but it works fine.
Here is a simple Js Fiddle example you can play with directly in the browser.
Follow me on Twitter where I post about game design, game development, Unity3d 2D, HTML5, applied games.