Pathfinding compute is WILD

I’m really shocked at these computed paths. Pathfinding service seems to be choosing the most wild path possible. Am I doing something wrong? What do you recommend for a better computed path?




local PathfindingService = game:GetService('PathfindingService')

local path = PathfindingService:CreatePath({
	AgentRadius = 5,
	AgentHeight = 6,
	WaypointSpacing = 5,
	AgentCanClimb = false,
	AgentCanJump = true,
	
	Costs = {
		--Safe = .01
		Jump = 0.01
	}
})

local drawPathWaypoint = true

function drawLine(startPosition, endPosition)
	local distance = (startPosition - endPosition).Magnitude
	local cframe = CFrame.lookAt(startPosition, endPosition) * CFrame.new(0, 0, -distance / 2)

	local box = Instance.new('BoxHandleAdornment')
	box.Size = Vector3.new(1, 1, distance)
	box.CFrame = cframe
	box.Color3 = Color3.new(0, 0.562844, 0.318822)
	box.Adornee = workspace
	box.Parent = workspace.Terrain
	
	game:GetService('Debris'):AddItem(box,1)
end

function showPath(waypoints)
	for index,waypoint in waypoints do
		local nextWaypoint = waypoints[index+1]
		
		if nextWaypoint then
			drawLine(waypoint.Position, waypoints[index+1].Position)
		end
		
		local point = Instance.new('SphereHandleAdornment')
		point.CFrame = CFrame.new(waypoint.Position)
		point.Adornee = workspace.Terrain

		game:GetService('Debris'):AddItem(point,1)

		if (waypoint.Action == Enum.PathWaypointAction.Jump) then
			point.Color3 = Color3.new(0.580728, 0.0667277, 0)
		end

		point.Parent = workspace.Terrain
	end
end

function drawPath(origin,destination)
	local success, errorMessage = pcall(function()
		path:ComputeAsync(origin.Position, destination.Position)
	end)

	if (success and path.Status == Enum.PathStatus.Success) then
		local waypoints = path:GetWaypoints()
		
		showPath(waypoints)
	end
end

while task.wait(1) do
	drawPath(workspace.Red,workspace.Blue)
end