I keep running into this issue where my pathfinding agent just
“Stutters.”
Ive looked on the Hub, but cant find anything that fixes this stuttering problem. I tried one solution that would see how close the agent is to the waypoint, but no luck.
This is my code:
local PFS = game:GetService("PathfindingService")
local Params = {
AgentRadius = 2,
AgentHeight = 5,
AgentCanJump = true,
}
function GetNextWaypoint()
local Path = PFS:CreatePath(Params)
Path:ComputeAsync(script.Parent.HumanoidRootPart.Position,script.TargetPart.Value.Position)
return Path:GetWaypoints()
end
while true do
if script.TargetPart.Value ~= nil then
local NextWaypoint = GetNextWaypoint()[2]
local JumpWaypoint = GetNextWaypoint()[3]
if NextWaypoint ~= nil and JumpWaypoint ~= nil then
if JumpWaypoint.Action == Enum.PathWaypointAction.Jump then
script.Parent.Humanoid.Jump = true
end
script.Parent.Humanoid:MoveTo(NextWaypoint.Position)
repeat
game["Run Service"].Heartbeat:Wait()
--print((NextWaypoint.Position - script.Parent.HumanoidRootPart.Position).Magnitude)
until (NextWaypoint.Position - script.Parent.HumanoidRootPart.Position).Magnitude <= Params.AgentHeight
end
end
end