Make behaviour trees in JavaScript
JavaScript CSS
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
LICENSE
README.markdown polished up docs Aug 23, 2011
base.js
changelog.txt
demo.js added warping to states; incorporated separation of state functions f… Aug 22, 2011
favicon.png
index.html
machine.js
main.css

README.markdown

Machine.js

Make behaviour trees in JavaScript

v1.1 [see changelog]

By mary rose cook

What is Machine.js?

Machine.js lets you use a hierarchical state machine to control a JavaScript object.

  • Define a behaviour tree as JSON.

    {
        identifier: "idle", strategy: "prioritised",
        children: [
            {
                identifier: "photosynthesise", strategy: "sequential",
                children: [
                    { identifier: "makeEnergy" },
                    { identifier: "grow" },
                    { identifier: "emitOxygen" },
                ]
            },
            { identifier: "gatherSun" },
            { identifier: "gatherWater" },
        ]
    };
    
  • For each leaf state, define a function that enacts the behaviour for that state. So, for the gatherSun state, define a function that gathers sun.

  • For each state, define a can function that returns true if the actor may move to that state. So, for the gatherSun state, define a function canGatherSun that returns true if the sun is out.

Licence

The code is open source, under the MIT licence. It uses Base.js by Dean Edwards.

Getting started

Download the repository. Open index.html in your browser to see the demo and documentation.