BehaviorTree2 - Create complex behaviors with ease!

Hello! It’s me, oniich_n. I’m back again with an update to the BehaviorTree module I ported to Roblox back in 2017. (wow so long ago)

With (a lot of) help from @tyridge77, I present to you…
BehaviorTree2!

This rewrite of the original module does away with a lot of the needless fluff needed from the original port, improving performance a ton! However, you can no longer “register” nodes using strings. Store them as variables instead or something. (I doubt many used this feature, though)

If you’ve already been using the old BehaviorTree module, you can simply replace it with this one and it should work out of the box unless you used the node registry.

If you don’t like coding a lot and want a visual tool to help with this, tyridge77 has also made this awesome editor plugin as an alternative!

Peep the GitHub repo for info on how to start using it today!

28 Likes

Published better documentation of how to use the module on the GitHub repo, and added a new weight attribute to tasks for use in the Random selector.
Peep the BTrees Visual Editor by @tyridge77 too.

6 Likes

Fixed the random selector woops

Hey, great tool, thank you and tyridge77 for making this possible. I have never attempted to make AI and this is helpìng me a lot.

I’d like to ask a few questions about interrumpting a node, I have an idling node and it’s something like this.

BehaviorTree2.Task:new({
    -- Start
    start = function(task, object)
        print("Start idling")
        object.isIdling = true
        object.idlingTimeStamp = tick()
    end,
    -- Run
    run = function(task, object)
        if object.isBeingAttacked then
            task:fail()	
        end
        if object.isIdling then
            print("Idling...")
            task:running()
            if (tick() - object.idlingTimeStamp) >= object.idlingTimeLimit then
                object.isIdling = false
                task:success()
            end
        end	
    end,
    -- Finish
    finish = function(task, object)
        print("Stopped idling")
        object.isIdling = false
    end
})

As you can see there is an if statement checking if the npc inside the object parameter has been damaged or attacked, so my question is: Is this the right way to break the node cycle? and if so can I do something like this?

finish = function(task, object)
    if task.status == "fail" then
        print("Stopped idling")
        object.isIdling = false
    end
end

Again thanks a lot.

1 Like