NPC stuck on small ledges

trying to get my npc to walk up this tiny ledge but its getting stuck, i dont wanna use jump since it’d look weird if it had to jump just to get over the smallest obstacle. I want the npc to just go up it like players do

Code:

	local rootPart = newMob.PrimaryPart
	local hum = newMob:WaitForChild("Humanoid")
	local mobInfo = MobIndex[mobModel.Name]
	
	self.mob = newMob
	self.mobInfo = mobInfo
	
	local path : Path = pathServ:CreatePath(mobInfo.Pathfinding)
	local targetPart = workspace.PathPart
	
	local waypoints
	local nextWaypoint
	local reachedConnection
	local blockedConnection
	local recalcConnection
	
	local function followPath()
		
		local success, errMsg = pcall(function()
			--local targetPos = Vector3.new(targetPart.Position.X, rootPart.Position.Y, targetPart.Position.Z)
			path:ComputeAsync(rootPart.Position, targetPart.Position)
		end)
		
		if success and path.Status == Enum.PathStatus.Success then
			
			local waypoints = path:GetWaypoints()
			
			for i, waypoint : PathWaypoint in ipairs(waypoints) do
				
				if i == 1 then continue end
				
				if blockedConnection then
					blockedConnection:Disconnect()
					blockedConnection = nil
				end
				if reachedConnection then
					reachedConnection:Disconnect()
					reachedConnection = nil
				end
				if recalcConnection then
					recalcConnection:Disconnect()
					recalcConnection = nil
				end
				
				hum:MoveTo(waypoint.Position)
				local recalc = false
				local pathReached = false
				
				blockedConnection = path.Blocked:Connect(function()
					recalcConnection:Disconnect()
					reachedConnection:Disconnect()
					recalc = true
				end)
				
				recalcConnection = RunServ.Heartbeat:Connect(function()
					if (waypoints[#waypoints].Position - targetPart.Position).Magnitude > 5 then
						print("recalc")
						recalcConnection:Disconnect()
						reachedConnection:Disconnect()
						recalc = true
					end
				end)
				
				reachedConnection = hum.MoveToFinished:Connect(function()
					reachedConnection:Disconnect()
					recalcConnection:Disconnect()
					pathReached = true
				end)
				
				repeat task.wait() until recalc == true or pathReached == true
				if recalc then return end
				
			end
			
		elseif errMsg then
			warn("Path not computed: "..errMsg)
		end
		
	end

	while task.wait() do
		if (rootPart.Position - targetPart.Position).Magnitude > 5 then
			print("follow")
			followPath()
		end
	end
2 Likes

can we see what’s inside MobIndex?

2 Likes

its just the pathfinding info:

Pathfinding = {
			AgentRadius = 12,
			AgentHeight = 6,
			AgentCanJump = true,
			AgentCanClimb = false,
			Costs = {
				Water = math.huge
			}
		}
3 Likes

Can you put a server Animate script in the NPC (or if the NPC is R6 or R15)? If not then you probably need to put an invisible wedge in the ledge’s place for the NPC to go up

1 Like

You can see if the character needs to jump using “PathWaypointAction”.

1 Like

I understand this, im trying to get the character to walk up the ledge (similar to the player) instead of jump

It could also be due to you enabling collissions in the legs? Anyways one more thing you can do is place trusses which basically help it “climb like the player”. Set its “AgentCanClimb” to true…

1 Like

have you set the Humanoid’s HipHeight property? You may need to increase it to around 1 or more depending on how big the model is if it is not set already.

I would recommend putting invisible wedges on the side of the stair, to make it easier for the ai to move around

i have its hipheight set to 1.7

If you don’t want the NPC to jump at all, you could put a small invisible wedge part lining that thin part to help the NPC up a bit.

edit: I was thinking about this one, there is a property on a humanoid called MaxSlopeAngle you may want to mess around with that a bit.

is the bottom of the NPC can-collide off? iirc, a default humanoid has the legs as can collide off

yeah everything is cancollide off except the root part, i have it set up relatively the same as the player character

Hey, did you manage to get this fixed, and how so?