I’ve been scripting an npc for a game, I want the npc to be able to chase after players and not collide with obstacles when trying to find a path towards them. To solve this problem, I’ve utilized the use of PathfindingService, however I’ve encountered a few issues with it, mostly when the npc is in an enclosed room with no way out.
When I try to find a path from the npc’s position to the target position, I get waypoints that are clearly impossible to traverse, colliding with obstacles and walls, sometimes even going through the ceiling.
Here’s a video portraying the issue (the walls have been made transparent to make it easier to see the npc and the waypoints)
Ideally the Path’s status should equal to Enum.PathStatus.NoPath, however it’s instead Enum.PathStatus.Success, occasionally it does equal to NoPath but thats mostly due to the npc flinging around which isn’t the issue for now
I’ve tried using PathfindingModifiers but that has not been successful for me, as shown in the video.
The walls are union parts that have pathfinding modifiers inside of them, with an infinite weight assigned to them to prevent the npc from walking on the wedges that are part of it.
I’ve also messed around with the agent params and that doesn’t really change the results in any meaningful way.
I believe the code to be functionally sound but I have attached a snippet for clarification
local pathfinder = Pathfinder(
npc,
{
AgentRadius = 3,
AgentHeight = 4,
AgentCanJump = true,
AgentCanClimb = false,
Costs = {
Wall = math.huge,
DontCross = math.huge
}
})
-- path instance is created in this manner
_path = PathfindingService:CreatePath(agentParams)
-- in the function for the pathfinder, that creates and generates the waypoints
self._path:ComputeAsync(self.npc:GetPivot().Position, target:GetPivot().Position)
local waypoints = self._path:GetWaypoints()
print(self._path.Status, #waypoints) -- Enum.PathStatus.Success most of the time
I’m at a loss on as to what to do to fix this issue, so any sort of help or pointers will be extremely helpful, please and thank you!







