I have been trying everything to get pathfinding to function smoothly. I've ensured that my path object is being recreated every iteration so that it doesn't get corrupted over time. I've verified that it only runs once every few seconds. I even disconnect any attached callbacks to avoid the possibility of multiple listeners being hit. And even across entirely different implementations I still run into the same exact issue. It works perfectly for about 30-45 seconds and after that the npc starts stuttering between points and slowing down, and with enough time it will stop completely. With pcall or without, it doesn't matter it behaves the same. I've been pulling my hair out and I hope there's someone here that can shine some light on my issue. Below in the first comment is what I'm using right now, I tried to strip out as much as I could to just isolate the issue.
#Pathfinding issues
1 messages · Page 1 of 1 (latest)
** You are now Level 1! **
-- Called when NPC finishes moving to a waypoint
local function onMoveFinished(reached)
if not reached then
warn("NPC couldn't reach waypoint. Repathing...")
isMoving = false
return
end
currentWaypointIndex += 1
if currentWaypointIndex <= #waypoints then
local nextWaypoint = waypoints[currentWaypointIndex]
Monster.Humanoid:MoveTo(nextWaypoint.Position)
else
-- Finished path
isMoving = false
end
end
-- Called if the NPC path gets blocked
local function onPathBlocked(blockedWaypointIndex)
if blockedWaypointIndex >= currentWaypointIndex then
warn("Path blocked. Recomputing path...")
isMoving = false
end
end
local function followPath(monster, destination)
isMoving = true
local agentParams = {
AgentRadius = 5,
AgentHeight = 5,
AgentCanJump = true,
AgentCanClimb = false
}
local path = PathfindingService:CreatePath({AgentParameters = agentParams})
-- Hook up events once
--path.Blocked:Connect(onPathBlocked)
path:ComputeAsync(monster.HumanoidRootPart.Position, destination)
if path.Status ~= Enum.PathStatus.Success then
warn("Pathfinding failed.")
isMoving = false
return
end
waypoints = path:GetWaypoints()
currentWaypointIndex = 1
-- Move to the first waypoint
monster.Humanoid:MoveTo(waypoints[currentWaypointIndex].Position)
end
local Player = game.Players:GetPlayers()[1]
Monster.Humanoid.MoveToFinished:Connect(onMoveFinished)
while true do
if not Player.Character then return end
if not isMoving then
followPath(Monster, Player.Character.HumanoidRootPart.Position)
end
task.wait(0.5)
end
Btw set the charactermodel serverowner to nil. That’s why it stutters after a couple seconds. Im on my phone so just look it up
It fixed my pathfinding
Oh that's fantastic, I haven't seen anything about that yet. I must have missed it. I'll give it a shot
You're the goat man, thank you that did it
can I mark this as solved?
Ya
oh there it is I got it, thank you again