Lerp stopping early at high fps

Hello there, I have been using lerp for a project of mine, but right after roblox rolled out the native fps unlocker, my lerps have been really acting up. I have also tried changing the wait time, but when I do that it jitters in mid air. Here is a snippet of my lerp usage:

 task.spawn(function()
		local dt = run.RenderStepped:Wait()
	for i = 0, 1, 0.01 do
				if ball.Parent:GetAttribute("CanUpdateLerp") == false then return end
				local rayparams = RaycastParams.new()
				rayparams.CollisionGroup = "ServerBall"
				rayparams.IgnoreWater = true
				local rayres = workspace:Raycast(ball.Position, ball.CFrame.LookVector * 3,rayparams )
				if rayres and rayres.Instance then
					if rayres.Instance.Name == "Net" then
						print("netdetected")
						for i = i, 1, 0.01 do
							if ball.Parent:GetAttribute("CanUpdateLerp")== false then return end
							if lv then
								ball.CFrame =CFrame.lookAlong(Vector3.new(CFrame.new(quadbezier(i * dt * 60, pos1, pos2, pos3)).p.X, CFrame.new(quadbezier(i * dt * 60, pos1, pos2, pos3)).p.Y, rayres.Instance.Position.Z - lv.Z * 2), lv)
								print(lv:Dot(ball.CFrame.LookVector))
							else
								ball.CFrame = CFrame.new(quadbezier(i * dt * 60, pos1, pos2, pos3).X, quadbezier(i * dt * 60, pos1, pos2, pos3).Y, rayres.Instance.Position.Z)
							end
							task.wait()
						end

					end
					return
				end
				if lv then
					
					ball.CFrame =CFrame.lookAlong(CFrame.new(quadbezier(i * dt * 60  , pos1, pos2, pos3)).p, lv)
					
				else
					ball.CFrame = CFrame.new(quadbezier(i, pos1, pos2, pos3))
				end
				task.wait()
				
	end

		end)

With this code, the lerp stops extremely early and I am not sure what to do.
Thank you in advance

Well you see, run.RenderStepped:Wait() is the time elapsed from the previous frame so it makes sense logically that if you’re at a higher fps, the function runs quicker. Try basing it off a fixed timestamp instead of a variable one

Try putting dt inside and the first of the for loop. Also, remove the task.wait() at the end since dt is already waiting for the delta time and see if it fixes it.

1 Like

Nevermind i just fixed it by using a runservice loop instead of a for loo[

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.