Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CooldownDecorator example #76

Open
j-o-phillips opened this issue Dec 26, 2023 · 0 comments
Open

CooldownDecorator example #76

j-o-phillips opened this issue Dec 26, 2023 · 0 comments

Comments

@j-o-phillips
Copy link

j-o-phillips commented Dec 26, 2023

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant