NPC uses PathfindingService
-My NPC frequently gets stuck on corners in the map (it is a basic maze)
-With multiple NPCs, they all follow the same path meaning they get stuck running behind each other instead of running next to them
I do not know how to fix this, it would be great if someone could help.
Code:
function PathfindToPos(Pos,OverWrite)
if Pathing == false then
spawn(function()
Pathing = true
local RenderedPath=PathfindingService:ComputeRawPathAsync(HRP.Position,Pos,500)
local RenderedPathCoordinates=RenderedPath:GetPointCoordinates()
local TimeOutNum = 2
local Ting = StopPathfinding
if Ting == true and OverWrite == true then
Ting = false
end
for _= 1,#RenderedPathCoordinates do
if not CanSee and Ting == false then
local Point=RenderedPathCoordinates[_]
local CurrentTime = tick()
repeat wait()
Humanoid:MoveTo(Point)
Ting = StopPathfinding
if Ting == true and OverWrite == true then
Ting = false
end
if (tick() - CurrentTime > TimeOutNum) or Ting then
break
end
until(HRP.Position-Point).Magnitude<5 or (tick() - CurrentTime > TimeOutNum) or CanSee or Ting
if (tick() - CurrentTime > TimeOutNum) then
warn("Time out")
end
if (tick() - CurrentTime > TimeOutNum) or CanSee then
break
end
end
end
Pathing = false
end)
end
end