PathfindingService is unable to generate paths when the NPC has to jump

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I want to create a bot which can do an obby.

  2. 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!

See the following bug report, could be linked to this. Try on a blank baseplate.

Roblox pathfinding is notorious for being just… horrible. However, you should attempt what @M_etrics said.

A tutorial showing how to use Pathfinding Links to jump gaps.
The other thing I’ve read is that if you have an older Place, or an old NPC model it may not work properly. The best result is starting with a new place and a newer NPC.

1 Like