First off, this is client-sided. no network shenanigans.
i have added rubber banding but it seems to be doing the opposite because the rig actually slows down due to jittering for no reason.
rubber banding code in question:
game:GetService("RunService").Heartbeat:Connect(function()
if following then
if (root.Position - plrhrp.Position).Magnitude >= 10 then
humanoid.WalkSpeed = values.ChaseSpeed.Value + 5
else
humanoid.WalkSpeed = values.ChaseSpeed.Value
end
end
end)
the chase speed is 19 by the way. the player sprinting speed is 20 (might have to tweak these in the future since it might be unbalanced but from playtests it seems to be fine so far.)
this is the main part of the Walk loop that handles pathing (it works perfectly before the walkspeed is dialed up. i have tried changing the waypoint it indexes in case that was the issue but that didnât solve anything. please ignore the comments.)
if following then --//yes i am checking for following twice I DON'T CARE
Target = plrhrp
end
local success, result = pcall(function()
path:ComputeAsync(root.Position, Target.Position)
end)
if not success then
warn(result)
task.wait()
return --//retry lol
end
local waypoints = path:GetWaypoints()
local success, result = pcall(function() --//there is a non-zero chance i will leave a place where it can't possibly go
if following then --//constantly updating the path, horrible for performance but it has to constantly recompute
--print(waypoints)
humanoid.WalkSpeed = values.ChaseSpeed.Value --//ACTUAL NOTE YOU ON DEVFORUM SHOULD READ: this is not the cause. commenting this out or changing the value still makes it stutter.
humanoid:MoveTo(waypoints[2].Position)
lastpos = waypoints[#waypoints]
return
else
hereâs an actual clip of it
as you can see, when i get further away from it, it starts stuttering as the walkspeed is increased. i have no idea what causes this.
i suggest adding a recompute cooldown so that its not done every second but i canât tell how often youâre computing due to your code. also, in piggy, they used a direct move to when the player was in sight, try that for more smoothness and less path usage.
lastly, try adding this
local lastWaypoint
if following then
if not lastWaypoint or (waypoints[2].Position - lastWaypoint).Magnitude > 1 then
humanoid:MoveTo(waypoints[2].Position)
lastWaypoint = waypoints[2].Position
end
end
this way you only send a moveto cal when the waypoint that is next changes not just spamming recompute. the jitter should disappear mostly
dunno if this will help but iâll try. the pathfinding here is gonna be significantly different considering it can hear doors, pull you out of hiding + the fact it has actual sprinting however this shouldnât interfere with those mechanics. thanks, iâll give it a shot!
this actually kills 2 birds with one stone because i wanted to make an âunstuckâ system where if it stays for longer than a few seconds in relatively the same place itâll just teleport to the next waypoint because usually while patrolling it just sometimes rams into very small corners (i have the radius set up properly, i genuinely have no clue why it does this and it only happens on 2 places. i literally had to make it recompute its path because i remember it tried to straight up go through an invisible wall and teleport up i guess while on some stairs which i genuinely doubt is my fault
The reason why it starts stuttering more as the walkspeed is increased is due to the fact that it completes each path faster, causing your current path recompute rate to not update fast enough, which is why you see the momentary stop. The simplest fix for this is to do humanoid:MoveTo(waypoints[3].Position) instead of âhumanoid:MoveTo(waypoints[2].Position)â
You will need to error handle if there is less than 3 waypointsârevert to second waypoint or sumn. A more complicated solution is to merely use simple MoveTo() inside of a while wait loop whenever the npc has direct sight of the player. It is best practice to combine both of these techniques.
Itâs not because of that. I stated In my initial post that I DID add something to increment the index amount if that was the case (and resetting it back to 2 once recomputing did finish) but that didnât solve the issue, as for the other solution in this thread: I havenât actually tested it yet because I posted this at 3 in the morning and I was starting to make bad coding decisions so I decided to stop for the night. Iâll try it today when I have time but it sounds promising.
I did add the check however in reverse, if it hasnât moved a full stud then return to restart the loop.
i have changed my code to this and nothing seems to have changed unfortunately.
if following then --//constantly updating the path, horrible for performance but it has to constantly recompute
--print(waypoints)
--//anti stuck + anti jittering
if rubberbanding and lastwaypoint then
if (waypoints[2].Position - lastwaypoint.Position).Magnitude < 1 and workspace.Technical.GameValues.OpeningDoor.Value == false then
print("why?")
print((waypoints[2].Position - lastwaypoint.Position).Magnitude)
stuck += 1
if stuck >= 30 then
print("Got stuck lol")
script.Parent:MoveTo(waypoints[2].Position)
end
return
end
end
stuck = 0
humanoid:MoveTo(waypoints[2].Position)
lastwaypoint = waypoints[2]
lastpos = waypoints[#waypoints]
return
sorry for the late response, iâve been pretty burnt out these past few days so i took a short break. i unfortunately can set only one post as the solution, but it was a combo of both of them that worked. thanks a lot!