Pathfinding Issue: Entity Sinking

I’ve been working on a pig that uses pathfinding to move. However, I have come across an issue where the waypoints that the pig generates sink into the ground, causing the pig to do the same when it moves. I have tested the code with humanoid rigs and the same issue occurs. I have written my code based on tutorials found on YouTube and the Developer Hub, but nothing changes.

This is what the waypoints currently do, regardless of what is trying to move:

Here is my current code:

local pfs = game:GetService("PathfindingService")
local pathParts = game.Workspace.Path
local start = rig.PrimaryPart
local finish = start.Position + Vector3.new(50, 0, 0)
local path = pfs:CreatePath()

path:ComputeAsync(start.Position, finish)
	
local waypoints = path:GetWaypoints()
	
for _, waypoint in pairs(waypoints) do
	local part = Instance.new("Part")
	part.Shape = Enum.PartType.Ball
	part.Material = Enum.Material.Neon
	part.Size = Vector3.new(.5, .5, .5)
	part.Position = waypoint.Position
	part.Anchored = true
	part.CanCollide = false
	part.Parent = pathParts
	rig:SetPrimaryPartCFrame(CFrame.new(waypoint.Position))
	wait(.1)
end

If anyone has any ideas as to what is wrong, it will be greatly appreciated.

Could you just dissect the position of the waypoint x, y, & z then offset the y by the height of the pig?

It’s completely normal, this happens because Pathfinding Service “draws” a line on the floor (I know, it’s not the best way to explain it).
To solve the issue of the pig sinking into the floor I recommend you to use

humanoid:MoveTo(waypoint.Position)
humanoid.MoveToFinished:wait()

Instead of setting its primary part CFrame

Sorry for bad English, it isn’t my native language

1 Like

Thank you, this worked really well.

Also, your English was fine – better than some native speakers I know :smile:

No problem, happy to hear that my English isn’t so bad