#pathfinding service choppy??

1 messages · Page 1 of 1 (latest)

uneven bridge
#

i need help I'm using path finding service to go to a part as like a transition scene but it's like choppy and I'm losing my mind over it this is on a server sided script too

    print("running...")
    local humanoid = npc and npc:FindFirstChildOfClass("Humanoid")
    local root = npc and npc:FindFirstChild("HumanoidRootPart")
    local destination = target.Position
    local function getpath()
        local pathParams = {
            ["AgentRadius"] = 2,
            ["AgentHeight"] = 5,
            ["AgentCanJump"] = false,
        }
        local path = PathfindingService:CreatePath()
        path:ComputeAsync(root.Position, destination)
        return path
    end
    local function moveToNextWaypoint()
        local path = getpath()
        for index, waypoint in pairs(path:GetWaypoints()) do
            humanoid:MoveTo(waypoint.Position)
            humanoid.MoveToFinished:Wait()
        end
    end
    moveToNextWaypoint()
    return true
end```

https://gyazo.com/6fa2d011f9877c6e62084a7dfd0dbc80
minor nova
charred flameBOT
#

studio** You are now Level 7! **studio

uneven bridge
#

it's still choppy even with ipairs

#

I'm calling the module function from a different module

#

I'm not sure if that has anything to do with it

minor nova
#

from what it seems, it stopping at every waypoint for a longer time than usual, u can try impl lookahead like ```lua
function util.WalkToTarget(npc, target)
print("running...")
local humanoid = npc and npc:FindFirstChildOfClass("Humanoid")
local root = npc and npc:FindFirstChild("HumanoidRootPart")
local destination = target.Position
local function getpath()
local pathParams = {
["AgentRadius"] = 2,
["AgentHeight"] = 5,
["AgentCanJump"] = false,
}
local path = PathfindingService:CreatePath(pathParams)
path:ComputeAsync(root.Position, destination)
return path
end
local function moveToNextWaypoint()
local path = getpath()
local waypoints = path:GetWaypoints()
for i, waypoint in ipairs(waypoints) do
humanoid:MoveTo(waypoint.Position)
repeat
task.wait()
if (root.Position - waypoint.Position).Magnitude < 2 and waypoints[i+1] then
humanoid:MoveTo(waypoints[i+1].Position)
break
end
until humanoid.MoveToFinished:Wait()
end
end
moveToNextWaypoint()
return true
end

#

maybe not the most accurate answer but it should cut down on the lag

uneven bridge
uneven bridge
#

i figured it out, since the script is server sided and my player's networkOwnership was clientsided i just needed it to be set to the server and set it back once i was done