flame_behavior_tree 0.1.3+3 copy "flame_behavior_tree: ^0.1.3+3" to clipboard
flame_behavior_tree: ^0.1.3+3 copied to clipboard

A bridge package that integrates behavior_tree package with flame.

flame

This is a bridge package that integrates the behavior_tree dart package with Flame engine.


Features #

This package provides a HasBehaviorTree mixin for Flame Components. It can be added to any Component and it takes care of ticking the behavior tree along with the component's update.

Getting started #

Add this package to your Flutter project using:

flutter pub add flame_behavior_tree

Usage #

  • Add the HasBehaviorTree mixin to the component that wants to follow a certain AI behavior.

    class MyComponent extends Position with HasBehaviorTree {
      
    }
    
  • Set-up a behavior tree and set its root as the treeRoot of the HasBehaviorTree.

class MyComponent extends PositionComponent with HasBehaviorTree {
  Future<void> onLoad() async {
    treeRoot = Selector(
      children: [
        Sequence(children: [task1, condition, task2]),
        Sequence(...),
      ]
    );
    super.onLoad();
  }
}
  • Increase the tickInterval to make the tree tick less frequently.
class MyComponent extends PositionComponent with HasBehaviorTree {
  Future<void> onLoad() async {
    treeRoot = Selector(...);
    tickInterval = 4;
    super.onLoad();
  }
}

Additional information #

When working with behavior trees, keep in mind that

  • nodes of a behavior tree do not necessarily update on every frame.
  • avoid storing data in nodes as much as possible because it can go out of sync with rest of the game as nodes are not ticked on every frame.
1
likes
160
points
4
downloads

Publisher

unverified uploader

Weekly Downloads

A bridge package that integrates behavior_tree package with flame.

Repository (GitHub)
View/report issues
Contributing

Topics

#flame

Documentation

API reference

Funding

Consider supporting this project:

opencollective.com
github.com
patreon.com

License

MIT (license)

Dependencies

behavior_tree, flame, flutter

More

Packages that depend on flame_behavior_tree