I have a humanoid NPC that will travel to a certain part using pathfinding service.
The path model as I see clearly, has a direct path to the target. But the status is deemed ClosestNoPath which means it cannot find a path so it gets the closest coordinates.
Why does this happen?
local path = game:GetService("PathfindingService"):ComputeRawPathAsync(script.Parent.HumanoidRootPart.Position, game.Workspace.SpecificObject.Position + Vector3.new(1, 0, 1), 500) if not path.Status == Enum.PathStatus.Sucess then print(path.Status) elseif path.Status == Enum.PathStatus.Success then script.Parent.Humanoid:MoveTo(path:GetCoordinates()[2]) end
And how can I fix it?
-Server script
-Inside a NPC model in Workspace
-Filtering Enabled game
This happens when no path is available to the start to the end, but the path provided will lead you to the closest bit of the end. Think of it like your NPC trying to go through the wall. It cannot go through the wall, but it will return ClosestNoPath and return the path which is closest to the end point, however not on the end point. If it does this for no reason, that is probably cuz roblox pathfinding sucks. I tried it and I needed to build in my own recalculations for the paths, because that is how terrible they are. So, to check if the path is wrong, you could just check the last coordinate and see if it is at the end.
if path[#path] == game.Workspace.SpecificObject.Position + Vector3.new(1, 0, 1) then print('Good path') else warn('Bad path') end
There is no way to fix ROBLOX's built in pathfinding, unless you want to make your own pathfinding.
Hope this helps!