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

Question: Is there a non-remember Selector? #66

Open
gonnavis opened this issue Oct 26, 2022 · 4 comments
Open

Question: Is there a non-remember Selector? #66

gonnavis opened this issue Oct 26, 2022 · 4 comments

Comments

@gonnavis
Copy link

gonnavis commented Oct 26, 2022

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
-----------------------------
@Calamari
Copy link
Owner

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?

@gonnavis
Copy link
Author

gonnavis commented Oct 27, 2022

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.

@Calamari
Copy link
Owner

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.

@gonnavis
Copy link
Author

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.

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

2 participants