Pathfinding NPC unable to calculate path when it's near meshparts/objects

Hello, recently i’ve been trying to make a pathfinding npc with a kinda complicated model. The thing is that for some reason, the npc gets stuck at some point even when it’s able to walk through, the pathfinding service seems to be unable to generate any path when the npc is close to an object even if the agentradius is almost at zero. Here’s a video of it:

(“Show decomposition geometry” is enabled to make hitboxes visible, that way there’s a clear vision of what’s happening)

Anyone knows why that might be happening? Here’s some parameters I use and the code for pathfinding (it uses promises and some other external things)

The agent radius set for this npc is 0.05, so I dont think that the agent radius is causing problems…

image

-- HEAVILY SIMPLIFIED TO MAKE IT EASIER TO UNDERSTAND
-- SCP == NPC

function Utilities.PathWalkToTarget(scp, targetPosition)
	Promise.new(function(resolve, reject, onCancel)
		onCancel(function()
			-- Makes the npc stop when cancelled
			scp.Humanoid:MoveTo(scp.RootPart.Position)
		end)
		
		local char_size = scp.Model:GetExtentsSize()
		local params = {
			AgentRadius = scp.Configuration.ModelRadius,--(char_size.X + char_size.Z) / 4,
			AgentHeight = char_size.Y,
			AgentCanJump = false,
			WaypointSpacing = 4,
		}

		local path = PathfindingService:CreatePath(params)
		path:ComputeAsync(scp.RootPart.Position, targetPosition)
		
		if path.Status == Enum.PathStatus.Success then

			local cancelled = false
			local CancelCurrentMovement
		
			for i, waypoint in pairs(path:GetWaypoints()) do
				if i <= 1 then continue end -- Ignores first waypoint if there are less than 60 mobs
				if cancelled then break end -- Stops loop if cancelled

				if not scp._Cache.JumpCooldown then
					if waypoint.Action == Enum.PathWaypointAction.Jump then
						scp.Humanoid.Jump = true
						scp._Cache.JumpCooldown = true
						Promise.delay(0.5):andThen(function()
							scp._Cache.JumpCooldown = false
						end)
					end
				end
				
				scp.Humanoid:MoveTo(waypoint.Position)
				scp.Humanoid.MoveToFinished:Wait()

				if i == #path:GetWaypoints() then
					resolve() -- (ENDS FUNCTION)
				end
			end
			
		else
			if scp.Name == "UnknownMonster_Event" then
				print("path find failed, status: ", path.Status.Name)
			end
			scp.Humanoid:MoveTo(scp.RootPart.Position)
			resolve()
		end
	end)
end

Are you using new algorithm Improving Pathfinding Quality With New Algorithm

By looking at the video it did seem the path was close to obstacle and once the NPC reached closed to the NPC it was having collisions.

If you are not using new algo please try it since we have tried to fix this kind of issues in the new algo and in case it is still happening with new algo please send us the repro case

1 Like

Yes, I didn’t knew about the new pathfinding algorithm that was implemented, it seems like a coworker of mine did enable the path. Anyways, yeah. It’s enabled.

image

Also, forgot to mention, the problem was that a part that was below the humanoidrootpart had collisions enabled, causing a lot of problems with the NPC movement and path generation. It’s solved now :smiley:

1 Like