You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? I want to create a bot which can do an obby.
-
What is the issue? The PathfindingService is unable to generate paths when the NPC has to jump
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
Below is my moduleScript.
local PathfindingService = game:GetService("PathfindingService")
local PathfindingHandler = {}
PathfindingHandler.__index = PathfindingHandler
function PathfindingHandler.new(humanoid)
local self = setmetatable({}, PathfindingHandler)
self.Humanoid = humanoid
self.AgentParameters = {
AgentRadius = 2,
AgentHeight = 3,
AgentCanJump = true,
AgentCanClimb = true,
WaypointSpacing = 2,
Costs = {Water = 20}
}
return self
end
function PathfindingHandler:MoveTo(targetPosition)
local path = PathfindingService:CreatePath(self.AgentParameters)
path:ComputeAsync(self.Humanoid.RootPart.Position, targetPosition)
local humanoid : Humanoid = self.Humanoid
path.Blocked:Connect(function(blockedWaypointIdx)
print('path blcoked')
end)
if path.Status == Enum.PathStatus.Success then
local waypoints = path:GetWaypoints()
for _, waypoint : PathWaypoint in pairs(waypoints) do
local waypointVisualizer = Instance.new("Part")
waypointVisualizer.Shape = Enum.PartType.Ball
waypointVisualizer.Size = Vector3.new(0.7, 0.7, 0.7)
waypointVisualizer.Parent = game.Workspace
waypointVisualizer.Position = waypoint.Position
waypointVisualizer.Anchored = true
print(waypoint.Action)
end
else
warn("Failed to find path")
end
end
return PathfindingHandler
Below is the implementation of it:
local npc = script.Parent
local PathfindingHandler = require(game.ReplicatedStorage.PathfindingHandler)
local Handler = PathfindingHandler.new(npc.Humanoid)
task.wait(2)
Handler:MoveTo(game.Workspace.TargetPos.Position)
Thank you!