Last updated:
0 purchases
flame behavior tree
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
copied to clipboard
Usage #
Add the HasBehaviorTree mixin to the component that wants to follow a certain AI behavior.
class MyComponent extends Position with HasBehaviorTree {
}
copied to clipboard
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();
}
}
copied to clipboard
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();
}
}
copied to clipboard
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.
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.