I have a weird issue with pathfinding an NPC, for some reason the NPC moves in a weird way, it’s like the NPC is returning back to a previous waypoint then continuing it’s path, here is how it looks like:
This is the code:
local Pathfinding = game:GetService("PathfindingService")
local Destination = game.Workspace.Part
for _, NPC in pairs(NPCs:GetChildren()) do
local HumanoidRootPart = NPC:FindFirstChild("HumanoidRootPart")
local Humanoid = NPC:FindFirstChild("Humanoid")
coroutine.resume(coroutine.create(function()
while true do
local BreakCoroutineLoop = false
local Path = Pathfinding:CreatePath({AgentRadius = 2, AgentHeight = 4, AgentCanJump = true})
Path:ComputeAsync(HumanoidRootPart.Position, Destination.Position)
local Waypoints = Path:GetWaypoints()
coroutine.resume(coroutine.create(function()
--//This is where I move the NPC to a waypoint:
for Index, Waypoint in pairs(Waypoints) do
if BreakCoroutineLoop then
break
end
if Waypoint.Action == Enum.PathWaypointAction.Jump then
Humanoid.Jump = true
end
Humanoid:MoveTo(Waypoint.Position)
Humanoid.MoveToFinished:Wait()
end
end))
wait(0.5)
BreakCoroutineLoop = true
end
end))
end
I only found this thread which had the same issue I have right now, however, nothing helped me to fix the issue.
Any help is really appreciated, thanks for reading.