Pathfinding Service Help


My NPC keeps walking into a wall like this

Code:

while true do
	local closest = math.huge
	local targetPos = nil
	
	for _, player in pairs(Players:GetPlayers()) do
		if player.Character == nil then
			continue
		end
		if (player.Character:GetPivot().Position-script.Parent:GetPivot().Position).Magnitude < closest then
			closest = (player.Character:GetPivot().Position-script.Parent:GetPivot().Position).Magnitude
			targetPos = player.Character:GetPivot().Position
		end
	end
	
	if targetPos == nil then
		targetPos = workspace._MovePoints:GetChildren()[math.random(1, #workspace._MovePoints:GetChildren())].Position
	end
	
	local path = PathfindingService:CreatePath({
		AgentRadius = 10,
		AgentHeight = 15,
		Costs = {
			Wall = math.huge
		}
	})
	
	local success, errormessage = pcall(function()
		path:ComputeAsync(script.Parent:GetPivot().Position, targetPos)
	end)
	
	if success and path.Status == Enum.PathStatus.Success then
		local part = Instance.new("Part")
		part.Size = Vector3.new(1,1,1)
		part.CanCollide = false
		part.Anchored = true
		part.Parent = workspace
		part.Position = path:GetWaypoints()[2].Position
		script.Parent.Humanoid:MoveTo(path:GetWaypoints()[2].Position)
		local cont = false
		task.spawn(function()
			script.Parent.Humanoid.MoveToFinished:Wait()
			cont = true
		end)
		
		path.Blocked:Connect(function()
			cont = true
		end)
		
		task.delay(3, function()
			cont = true
		end)
		
		repeat task.wait() until cont
	else
		warn(errormessage)
	end
	
	task.wait()
end

Hey @asherppan, have you tried the new algo which should resolve this? Here’s the article; Improving Pathfinding Quality With New Algorithm.

I just tried to turn it on and this is what happens.

it seems that the pathfinding AI is attempting to jump even though you dont have any jump logic, the default value for AgentCanJump is true (PathfindingService | Documentation - Roblox Creator Hub) try setting this to false to prevent the AI from trying to jump on the side of the wall without having any sort of logic to handle jumping.

I set AgentCanJump to false and it just takes a longer route and gets stuck anyways.
image
I feel like what should happen is since I set AgentRadius to 10 it should account for the size of my rig and make sure way points are not within 10 studs of a wall (which it obviously isn’t because when it gets stuck the way point is about 3 studs away from the wall).