behaviourtree.lua
behaviourtree.lua copied to clipboard
Arguments to node instances
I'd like to provide arguments to an instance of a task. Currently, I do that by creating an entire new node type:
local function create_action_task(params)
return BehaviourTree.Task:new({
run = function(self, entity)
local action = entity:set_action_if_not_set(unpack(params))
if action:is_complete() then
self:success()
else
self:running()
end
end,
})
end
local bt = BehaviourTree:new({
tree = BehaviourTree.Sequence:new({
nodes = {
create_action_task({ rvwp.entity.actions.go_to, Vector:new(4, 5, 0) }),
create_action_task({ rvwp.entity.actions.go_to, Vector:new(16, 5, 1) }),
}
})
})
bt:setObject(entity)
is there a better way to do this?