Pathfinding NPC gets stuck, doesn't jump on top of table!


This gif explains it from server view.
The NPC even recalculates the path but returns to the one that does not work because it doesn’t jump it when my player is on the other side!

My code:

function pathFind(position, target)
	local ignore = {nugget,target,workspace.Rays, CollectionService:GetTagged("NotSafeCharacters")}
	
	local rayParams = RaycastParams.new()
	rayParams.FilterType = Enum.RaycastFilterType.Blacklist
	rayParams.FilterDescendantsInstances = ignore
	local startPosition = (Root.CFrame * CFrame.new(0,0,-2)).Position
	local endPosition = position - startPosition
	
	local result = workspace:Raycast(Root.CFrame.Position, endPosition, rayParams)
	
	local heightDiff = false
	local yHeight = Root.Position.Y
	if Root.Position.Y > -(Root.Position.Y - position.Y) then
		yHeight = position.Y
		--Humanoid.Jump = true
	end
	
	if result then
		local connection;
		local success, errorMessage = pcall(function()
			local newPos = Vector3.new(position.X + math.random(-3,3), yHeight, position.Z + math.random(-3,3))
			path:ComputeAsync(Root.CFrame.Position, newPos)
		end)
		if not success or path.Status ~= Enum.PathStatus.Success then
			pathFind(roamPoints.Spawn.Position, roamPoints.Spawn)
			return
		end
		--Humanoid.WalkSpeed = 17
		local waypoints = path:GetWaypoints()

		local distance = (Root.CFrame.Position - result.Position).Magnitude
		
		if path and waypoints or checkw(waypoints) then
	
			if checkw(waypoints) ~= nil and checkw(waypoints).Action == Enum.PathWaypointAction.Walk then
				Humanoid:MoveTo( checkw(waypoints).Position )
				Humanoid.Jump = false
			end

			if checkw(waypoints) ~= nil and checkw(waypoints).Action == Enum.PathWaypointAction.Jump then
				connection = Humanoid.Changed:connect(function()
					Humanoid.Jump = true
				end)
				Humanoid:MoveTo( waypoints[3].Position )
			--else
			--	Humanoid.Jump = false
			end

			if connection then
				connection:Disconnect()
			end
		else
			for i = 2, #waypoints do
				Humanoid:MoveTo( waypoints[i].Position )	
			end
		end
	else
		--local distance = (Root.CFrame.Position - position).Magnitude
		Humanoid:MoveTo(position)
	end
end

Basically as you can see it should jump I am printing but seems like the first waypoint on the EDGE of the table is not counting as jump so the NPC just gets stuck. Any idea how to fix?

Edit: fixed it by raising the table by 0.2 studs? lol

1 Like