Pathfinding Behavior Tree

For the AIs in my game I want to use behavior trees so I am currently using the BehaviorTrees3 by Defaultio and I want to make this code a lot more better since it feels like there is a much more better way than this

Module Script :

function AI:Move(vector)
	if self.BlackBoard.Moving.IsMoving == true then
		if self.BlackBoard.Moving.Completed == true then
			self.BlackBoard.Moving.Completed = false
			self.BlackBoard.Moving.IsMoving = false
			return true
		else
			return false
		end
	else
		task.spawn(function()
			local path = PathService:CreatePath()
			path:ComputeAsync(self.root.Position, vector)
			
			if path.Status == Enum.PathStatus.Success then
				local waypoints = path:GetWaypoints()
				self.BlackBoard.Moving.IsMoving = true
				
				for _,v in pairs(waypoints) do
					if v.Action == Enum.PathWaypointAction.Jump then
						self.human.Jump = true
					end
					self.human:MoveTo(v.Position)
					self.human.MoveToFinished:Wait()
				end
				
				self.BlackBoard.Moving.Completed = true
			end
		end)
	end
end

Node inside the Tree

function task.run(obj)
	local Blackboard = obj.Blackboard
	
	local location = obj.root.Position + Vector3.new(math.random(-100,100), 0, math.random(-100,100))
	
	local results = obj.AI:Move(location)
	
	if results == true then
		return SUCCESS
	end
	
	return RUNNING
end

It’s not a proper moving system since I want to test out how I would do this

1 Like