Behavior Trees in Roblox?

I want to achieve behavior trees, now I found many posts on a specific BTrees Plugin, which looked awesome, but didn’t have proper tutorials (atleast I couldn’t find any). I went to YouTube and BTrees’ own GitHub, and it had scripted demos, but didn’t really have a “tutorial”. Just API.

So, as I, anyway wanted simple Behavior trees, I could just pretty much write code.

Now I’m not familiar with how BTrees are actually coded across engines, but I was wondering it was something like

while true do
 if farfromplayer then
  gotoPlayer()
 elseif farfromPlayer and NightTime then
  stayIdle()
 end
end
2 Likes

Really wonderful plugin for creating behaviour trees. You can set them up in any way you want with the visual editor and write code in them if you like as well. Then, all you need to do is run the tree. Pretty sure in my game we just have the run function called every frame and let the module handle the rest of the heavy lifting.

2 Likes

the condition of the elseif can never be true, so the stayIdle branch is never reached. Just FYI.

As for behavior trees, what you’ve coded is more like a decision tree. Behavior trees are quite a bit more complicated. You can see an explanation of the difference here. I’m sure you’ve done some reading already but I like this article: Behavior trees for AI: How they work

Are you sure behavior trees are right for your situation though? Have you considered decision trees or state machines?

1 Like

I have indeed considered State Machines, and am currently working with them, but however, I just wanted to know what behavior trees code looks like. Decision trees work fine at the moment, I was just curious :stuck_out_tongue:

1 Like