Heyo, I’m trying to make an NPC that follows a randomly generated path using pathfinding but I’ve ran into a problem and I’m completely stomped on how to fix it.
My NPC keeps getting stuck on seemingly nothing when It has to walk on a flat MeshPart but this dosen’t occur when it walks on a normal Part. Do MeshParts effect PathFinding or is it just bad code?
Walking on part:
Walking on meshpart:
Code:
local human = script.Parent:WaitForChild("NPC")
local torso = script.Parent:WaitForChild("Head")
local Distance = 50
local Distance2 = -50
local StandTime = 0.1
local clone = script.Parent:Clone()
function move()
local randX = math.random(Distance2,Distance)
local randZ = math.random(Distance2,Distance)
local goal = torso.Position + Vector3.new(randX,0,randZ)
local path = game:GetService("PathfindingService"):CreatePath()
path:ComputeAsync(torso.Position, goal)
local waypoints = path:GetWaypoints()
if path.Status == Enum.PathStatus.Success then
for _, waypoint in pairs(waypoints) do
if waypoint.Action == Enum.PathWaypointAction.Jump then
human.Jump = true
end
human:MoveTo(waypoint.Position)
human.MoveToFinished:Wait(2)
end
else
wait(2)
end
end
human.Died:Connect(function()
wait(1)
clone.Parent = workspace
game:GetService("Debris"):AddItem(script.Parent,0.1)
end)
while wait(StandTime) do
move()
end