Def-behavior-tree - library for creating complex AI behaviors

def-behavior-tree - a library for creating behavioral trees that allow you to easily manage advanced NPC behaviors in your game.
It’s functional and event-driven, which means that the next nodes are activated only when the previous one returns success or false.
It also have ability to run any node from any moment, so you can easily save active node ID and run it when game load for example.

Library Github → s-kania/def-behavior-tree: Behavior tree library for Defold engine (github.com)

More about BT trees → Behavior trees for AI: How they work (gamedeveloper.com)

Implemented nodes

  • Composite
    • Sequence
    • Selector
    • Random
    • RandomWithChances
  • Decorator
    • AlwaysFailDecorator
    • AlwaysSucceedDecorator
    • ChanceDecorator
    • InvertDecorator
    • RepeatUntilFailDecorator
  • Task (basic node)

Video
It shows Roids example, but with AI steering instead of player input:
Example for def-behavior-tree library.

Let me know what you think, especially if you start using this library :slight_smile:

14 Likes

Nice work, very well done, thank you for this library.

I have a similar long-running(since 2021) project that I haven’t found enough time to fix the issues but it is almost there.

Just a suggestion, if you allow me:
I found creating behavior trees by writing code very hard, especially the complex ones. It quickly becomes a mess, making it hard to read and update (just my opinion, of course).

So, I’m using the old js based behavior tree editor. The editor is here: Behavior Tree Editor. It just uses generic JSON for exporting the tree. It might not suit your project well, but maybe you can consider adding a JSON parser.
And the runtime is here if you want to take a look: https://github.com/selimanac/defold-b3

6 Likes

Thanks! That’s good point. I’ll do something with this editor when I will need to do more complex tasks in my game :smiley: