So I haven’t used this service in ages lol, I think I’m figuring it out, but one thing I noticed is that there’s a considerably large delay when I attempt to move the player to each path node for the first time. After the delay, it starts performing more responsively.
Any clue as to what I missed here? Thanks
Here’s a code snippet:
local function moveCharToNode(nodePos) --//Attempts to move the player to the specified node position
local human = char.Humanoid
local rootPart = char.PrimaryPart
human:MoveTo(nodePos.Position)
local TIMEOUT_TIME = 5
local DISTANCE_TO_NODE = 3
local timeElapsed = 0
repeat --//Implement a timeout to prevent infinite yields
local dt = runService.Heartbeat:Wait()
local isAtNode = (rootPart.Position - nodePos.Position).Magnitude <= DISTANCE_TO_NODE
timeElapsed += dt
until not isCharActive() or timeElapsed >= TIMEOUT_TIME or isAtNode
end
local function moveCharToWaypoints() --//Attempts to the move the character to each waypoint in the path
local waypoints = currentPath:GetWaypoints()
for _, waypoint in ipairs(waypoints) do
if not isCharActive() then return end
moveCharToNode(waypoint)
end
end
function pathfindingController:moveCharacterToPoint(targetLocation) --//Handles moving the character to the specified point
char = player.Character
if not isCharActive(char) or isRunning then return end --//Make sure the character exists
isRunning = true
setPlayerControlsEnabled(false)
currentPath:ComputeAsync(char.PrimaryPart.Position, targetLocation)
if currentPath.Status ~= Enum.PathStatus.Success then warn("Path was not made successfully") return end
moveCharToWaypoints()
isRunning = false
end