Calamari / BehaviorTree.js

An JavaScript implementation of Behavior Trees.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to make parallel behavior?

crapthings opened this issue · comments

like walking and smoking?

sorry I'm very new to game dev, I can't figure out how to do this with BehaviorTree.js

Hey ho.

That is hard to answer on a general term, since I think it depends on how your whole system is structured.
But one way that comes to my mind is to have two trees active for one actor. One that controls the target (like where to go, or if to stay and idle) and one what to do (while walking somewhere, or idling around), maybe depending on the target (might also be an enemy to attack).

Or another way could be one Task that activates the walking animation, if there is nothing more urgent to do, and on the next tree run, when the character is still walking that node will be a failure, since it has not to start walking, and then the btree chooses to also smoke, since the hands are free.

Does this ideas help?

I've been watched some BTS video tutorials that show there's a "parallel node" like "sequence node". but I can't find it with

https://github.com/Calamari/BehaviorTree.js/tree/master/src

parallel task

https://www.youtube.com/watch?v=Uj1pm2T-z8w&list=PLCPL5IYZm1NLVVxJx3-CFTLuHvLbCgmzk&index=5

maybe there's another approach that like you mention.

I was thinking it's something ah... kind of like async parallel

http://caolan.github.io/async/v3/docs.html#parallel

or maybe promise.all

promise.all([task1, task2]).then(next)

compare to a sequence node

http://caolan.github.io/async/v3/docs.html#series

I will use phaser 3 for my game, it's an idle-type game.
player and NPC(enemy) autonomous behaviors

a simple example that I can imagine is a player moving and casting spells at the same time after finding enemy

but anyway I will try two trees, thanks @Calamari

Thanks for the video.
That is indeed an interesting node to have. And it should not be difficult to build these nodes at all. Maybe I'll build something, if I have the time.

I figured, that this is/was not as easy to implement as I thought it would, since that kind of node would need to knowledge of previous runs, which is only available through the introspector by now.
So that would need a kind of rewrite. I am trying this out right now, but have to check the performance implications that will have.
But since that is a bigger thing that will only happen on the basis of the new typescript version, so it will be released as version 3 then. Just letting you know. :-)

@crapthings If you like, you can check out the new parallel nodes (they are pretty much as described in the video you mentioned). They should help you build your project.

Since I want to test the changes out a bit more, because that branch is based upon the typescript rewrite, it'll stay in the parallel branch for a bit. But it should be easy for you to pull that instead of a regular release number.

Let me know what you think and/or if you find a bug or something.

I've cloned the repo and switch to parallel branch

Build Result Error: There was a problem with a file build result.
Error: Unexpected: Unscanned package import "behaviortree" couldn't be built/resolved.

{
  "scripts": {
    "dev": "snowpack dev",
    "start": "snowpack dev",
    "build": "snowpack build"
  },
  "devDependencies": {
    "@snowpack/plugin-postcss": "^1.4.3",
    "autoprefixer": "^10.4.2",
    "postcss": "^8.4.5",
    "snowpack": "^3.8.8",
    "standard": "^16.0.4",
    "tailwindcss": "^3.0.12"
  },
  "dependencies": {
    "behaviortree": "file:../BehaviorTree.js",
    "dayjs": "^1.10.7",
    "lodash": "^4.17.21",
    "phaser": "^3.55.2",
    "phaser3-rex-plugins": "^1.1.65",
    "phaser3-scrolling-camera": "^2.0.2"
  }
}

If you have cloned it locally, you could go with removing it from the "package.json" in your project.
In the cloned directory you can do npm link and in your project directory you can just used the linked version npm link behaviortree. Then it should work (maybe you have to do npm run build in the cloned repo as well, but I think that should be done automatically before the linking.)