CooldownDecorator example
Hi, This package is really useful but I'm struggling to implement a cooldown Decorator. Could you advise me why this doesn't work: First i register the task:
BehaviorTree.register(
"fire",
new Task({
run: function (enemyShip) {
enemyShip.fireMissile();
return SUCCESS;
},
})
);
Then i decorate it:
const decoratedTask = new CooldownDecorator({
node: "fire",
config: 5,
});
Then I use it in the tree:
const tree = new Selector({
nodes: [
new Sequence({
nodes: [
new Task({
run: function (enemyShip) {
return enemyShip.checkIsInMissileRange(environmentDetails)
? SUCCESS
: FAILURE;
},
}),
new Task({
run: function (enemyShip) {
enemyShip.haltToStop(environmentDetails, setTargetShipDetails);
return SUCCESS;
},
}),
decoratedTask,
],
}),
new Sequence({
nodes: [
new Task({
run: function (enemyShip) {
enemyShip.moveToTarget(environmentDetails, setTargetShipDetails);
return SUCCESS;
},
}),
],
}),
],
});
However the task 'fire' is still called for every step of the behaviour tree. Thanks in advance!
Should it be:
const decoratedTask = new CooldownDecorator({ node: "fire", config: { cooldown: 5}, });
Hiho. Sorry @j-o-phillips for the veeeery late reply, but MikalDev is right with his answer. Also note that the current version of CooldownDecorator is counting seconds, in case you wander what the 5 actually means. So the child node is only called again after 5 seconds (not 5 steps).