#Pathfinding Jittering / Stuttering / Lagging?

1 messages · Page 1 of 1 (latest)

unique condor
#

While using the pathfinding service, I notice that after maybe 20-30 seconds of pathfinding it will start to jitter. It is almost like the rig is teleporting short distances. I am wondering how I can prevent this


local npc = script.Parent
local humanoid = npc:WaitForChild("Humanoid")

local location1 = workspace.Location1
local location2 = workspace.Location2
local location3 = workspace.Location3


local function followPath(destPart)
    
    -- creates the settings for the path
    local path = PathfindingService:CreatePath({
        AgentRadius = 3,
        AgentHeight = 6,
        AgentCanJump = true,
        -- Costs = {}
    })
    
    -- Computes the path from param 1 to param 2
    local success, errorMessage = pcall(function()
        path:ComputeAsync(npc.PrimaryPart.Position, destPart.Position)
    end)
    
    -- if the path was successfully created, then...
    if success and path.Status == Enum.PathStatus.Success then
        
        -- get waypoints and move to each one of them
        for _, waypoint in path:GetWaypoints() do
            if waypoint.Action == Enum.PathWaypointAction.Jump then
                humanoid.Jump = true
            end
            
            -- move humanoid to the next waypoint
            humanoid:MoveTo(waypoint.Position)
            
            -- go to next waypoint once current wp is reached
            local status = humanoid.MoveToFinished:Wait()
            
        end
    end
end

while true do
    followPath(location1)
    wait(10)
    followPath(location2)
    wait(10)
    followPath(location3)
    wait(10)
    followPath(workspace.Adsfinity.PrimaryPart)
    wait(10)
end```
fiery copper
#

have u tried setting network ownership of the npcs primary part to nil?

unique condor
#

no, I read a post about that being a solution but I thought that was for the pathfindign being run locally or smth. Should that fix the issue?

fiery copper
#

it should yes

unique condor
#

And do I do that once or do I need to do it multiple times per smth?

fiery copper
#

i suggest using cansetnetworkownership inside the follow path function and setting it

unique condor
#

So something like this?:

    for _, v: BasePart in pairs(self.Character:GetDescendants()) do
        if v:IsA("BasePart") and v:CanSetNetworkOwnerShip() then
            v:SetNetworkOwner(nil)
        end
    end
)```
fiery copper
#

no not like that

#

just set it when it starts a path

#

and u only have to do the primary part

#

or humanoidrootpart

#

most likely the latter

unique condor
#

So just this?: npc.PrimaryPart:SetNetworkOwner(nil)

fiery copper
#

ye

#

make sure to check canset first tho

#

in case it errors

unique condor
#

works great now tysm

fiery copper
#

u welcome