Pathfind npc refuses to jump off a ledge into his impending doom

Hello!
Ive been working on a pathfind npc that DOESNT USE FREE MODELS!!! YEAAAA!!!

However, when im trying to get the npc to jump off a ledge to pursue the player, they just refuse to do it. they probably value their kneecaps.

Heres a video of the problem:

ignore the end

Heres my code:

-- ok so i kinda copied this from the roblox documentation on pathfinding but ignore that 
local ai = script.Parent

local humanoid = ai:WaitForChild("Humanoid")
local torso = ai:WaitForChild("Torso")
local hrp = ai:WaitForChild("HumanoidRootPart")

local pathfind_service = game:GetService("PathfindingService")
local path = pathfind_service:CreatePath({
	AgentRadius = 1.5;
	AgentHeight = 6;
	AgentCanJump = true;
	Costs = {
		Climb = 2;
	}
	
})

local waypoints
local next_index
local reached
local blocked

local visualize = true
local visualized_waypoints = {}

function follow_path(destination)
	local success, error_mes = pcall(function()
		path:ComputeAsync(hrp.Position, destination)
	end)
	
	if visualize then
		for i, v in ipairs(visualized_waypoints) do
			v:Destroy()
		end

		table.clear(visualized_waypoints)
	end
	
	if success and path.Status == Enum.PathStatus.Success then
		waypoints = path:GetWaypoints()
		
		blocked = path.Blocked:Connect(function(index)
			if index > next_index then
				blocked:Disconnect()
				follow_path(destination)
			end
		end)
		
		if visualize then
			for i, waypoint in pairs(waypoints) do
				local part = Instance.new("Part")
				
				part.Anchored = true
				part.CanCollide = false
				part.Parent = workspace
				part.Position = waypoint.Position
				
				part.Shape = Enum.PartType.Ball
				part.Material = Enum.Material.Neon
				part.Size = Vector3.new(0.5, 0.5, 0.5)
				part.Color = Color3.fromRGB(255, 255, 255)
				
				table.insert(visualized_waypoints, part)
			end
		end
		
		if not reached then
			reached = humanoid.MoveToFinished:Connect(function(reached_)
				if reached_ and next_index < #waypoints then
					next_index += 1
					humanoid:MoveTo(waypoints[next_index].Position)
					
					if waypoints[next_index].Action == Enum.PathWaypointAction.Jump then
						humanoid.Jump = true
					end
				else
					reached:Disconnect()
					blocked:Disconnect()
				end
			end)
		end
		
		next_index = 2
		humanoid:MoveTo(waypoints[next_index].Position)
		if waypoints[next_index].Action == Enum.PathWaypointAction.Jump then
			humanoid.Jump = true
		end
	else
		warn(error_mes)
	end
end

while task.wait() do
	follow_path(workspace.Target.Position)
end

Any help is appreciated.

1 Like

Put print("Blocked!") inside the blocked function to let you know in the Output window when the script registers a path.Blocked event.

If so then this might help: Character Pathfinding | Documentation - Roblox Creator Hub

Tried it, it wasnt printing.

blocked = path.Blocked:Connect(function(index)
	print("that sucks")
	if index > next_index then
		blocked:Disconnect()
		follow_path(destination)
	end
end)

Output: nothin

1 Like