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.