Calamari / BehaviorTree.js

An JavaScript implementation of Behavior Trees.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question: Is there a non-remember Selector?

gonnavis opened this issue · comments

commented

Hello, I think the current Selector will remember the last RUNNING node, and in next tick running directly start from it, ignoring any siblings in front of it, even the sibling at font will return SUCCESS now, right?

Test codes:
import { BehaviorTree, Sequence, Selector, Task, SUCCESS, FAILURE, RUNNING } from 'behaviortree'

let count = 0;
const blackboard = {};

BehaviorTree.register('000', new Task({
  run: function (blackboard ) {
    console.log('000')
    if (count <= 3) {
      return FAILURE
    } else {
      return SUCCESS
    }
  }
}))
BehaviorTree.register('111', new Task({
  run: function (blackboard ) {
    console.log('111')
    return RUNNING
  }
}))

const tree = new Selector({nodes: [
  '000',
  '111',
]})

const bTree = new BehaviorTree({
  tree: tree,
  blackboard: blackboard
})

function step() {
  bTree.step()
  console.log('-----------------------------')
  count++;
  if (count < 10) setTimeout(step, 1000);
}
step();
Output:
000
111
-----------------------------
111
-----------------------------
111
-----------------------------
111
-----------------------------
111
-----------------------------
111
-----------------------------
111
-----------------------------
111
-----------------------------
111
-----------------------------
111
-----------------------------

I want to ask that, is there a non-remember Selector, which check all children from first until fail one every tick?

Expected output:
000
111
-----------------------------
000
111
-----------------------------
000
111
-----------------------------
000
-----------------------------
000
-----------------------------
000
-----------------------------
000
-----------------------------
000
-----------------------------
000
-----------------------------
000
-----------------------------

Contraquestion: Why would you return RUNNING in the first place, if you don't want that task to go on (keep running)? Why not simply return SUCCESS in that case?

commented

https://docs.unrealengine.com/4.27/en-US/InteractiveExperiences/ArtificialIntelligence/BehaviorTrees/BehaviorTreeQuickStart/
image

Say in this structure, I want FindRandomPatrol only run once until moved to dest, because of I don't want change dest when moving.
So I let Move to return RUNNING, then I achieved this goal, and node 111 will return RUNNING too.

But I still want the AI to chase player immediately if Has Line Of Sight to player when AI is moving.
So I need a non-remember version Selector in this case.

Thanks for that very clear picture. I like.

Currently, I would solve it, with just letting "Move To" put a target location into the blackboard (maybe calling it "Select Target Location") and return SUCCESS, so there can be node in the selector before that one that actually moves the actor as long as a target location is set.

But that is just from the top of my head. I'll think about this further and do some reasearching, maybe you've got a point there. I am intrigued.

commented

Currently, I would solve it, with just letting "Move To" put a target location into the blackboard (maybe calling it "Select Target Location") and return SUCCESS, so there can be node in the selector before that one that actually moves the actor as long as a target location is set.

This should be a good way too. Many thanks! I'll try.