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

How to make parallel behavior? #58

Open
crapthings opened this issue Jan 1, 2022 · 7 comments · May be fixed by #60
Open

How to make parallel behavior? #58

crapthings opened this issue Jan 1, 2022 · 7 comments · May be fixed by #60

Comments

@crapthings
Copy link

crapthings commented Jan 1, 2022

like walking and smoking?

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

@Calamari
Copy link
Owner

Calamari commented Jan 1, 2022

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?

@crapthings
Copy link
Author

crapthings commented Jan 1, 2022

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

@Calamari
Copy link
Owner

Calamari commented Jan 1, 2022

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.

@Calamari
Copy link
Owner

Calamari commented Jan 5, 2022

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. :-)

@Calamari Calamari linked a pull request Jan 10, 2022 that will close this issue
@Calamari
Copy link
Owner

@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.

@crapthings
Copy link
Author

crapthings commented Jan 11, 2022

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"
  }
}

@Calamari
Copy link
Owner

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.)

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

Successfully merging a pull request may close this issue.

2 participants