My pathfinding NPC is able to successfully path to a truss, but becomes immobile once it reaches a position close to the top. I’m not sure why is stops moving here - any ideas? Attached is an image of the issue and the script I am using to pathfind.
The script:
local Pathfind = game:GetService("PathfindingService")
local module = {}
function module.PathfindToLocation(char, goal: Vector3)
local hum: Humanoid = char:WaitForChild("Humanoid")
local blocked
local done
local doneConnect
local nextWaypoint = 0
local path: Path = Pathfind:CreatePath({
AgentCanJump = true,
AgentCanClimb = true
})
local success, errorMessage = pcall(function()
path:ComputeAsync(char.PrimaryPart.Position, goal)
end)
if success and path.Status == Enum.PathStatus.Success then
local waypoints: {PathWaypoint} = path:GetWaypoints()
blocked = path.Blocked:Connect(function(blockedWaypointIdx)
print("Path blockd")
if blockedWaypointIdx > nextWaypoint then
module.PathfindToLocation(char, goal)
doneConnect:Disconnect()
blocked:Disconnect()
end
end)
if not doneConnect then
doneConnect = hum.MoveToFinished:Connect(function(reached)
if reached and nextWaypoint < #waypoints then
nextWaypoint += 1
hum:MoveTo(waypoints[nextWaypoint].Position)
if waypoints[nextWaypoint].Action == Enum.PathWaypointAction.Jump and not (hum:GetState() == Enum.HumanoidStateType.Climbing) then
hum.Jump = true
end
else
doneConnect:Disconnect()
blocked:Disconnect()
end
end)
end
nextWaypoint = 2
hum:MoveTo(waypoints[nextWaypoint].Position)
else
print(errorMessage)
end
end
return module