Hello; I am having issues with adjusting lerps to the players fps. It is for a volleyball system I am creating, and when I try lerping using an estimated fps, it can either be too fast or too slow, and a lag spike would cause issues, but when I use the constantly changing deltatime, the ball jitters. Here is a video using the actual deltatime:
robloxapp-20241228-2159061.wmv (817.5 KB)
as you can see, it is extremely jittery and unplayable, but I would like to be able to slow down and speed up the lerp to adjust to the fps, if possible.
Here is my code:
local module = {}
local run = game:GetService("RunService")
local function lerp(a,b,c)
return a + (b-a) *c
end
local function quadbezier(t, a, b ,c)
local l1 = lerp(a,b,t)
local l2 = lerp(b,c,t)
local quad = lerp(l1,l2,t)
return quad
end
function module.Curve(pos1, pos2,pos3, ball, lv, char)
if run:IsClient() then
local frontraycast = char.HumanoidRootPart.CFrame.LookVector * 3
local i = 0
local stillupd = false
local truedt = run.RenderStepped:Wait()
print(truedt)
local con
local netcon
local lerpid = math.random(0,100000000)
ball:SetAttribute("LerpID", lerpid)
local multby = 60
con = run.RenderStepped:Connect(function(dt)
if truedt < dt then
truedt = dt
elseif truedt > dt then
truedt = dt
end
stillupd = true
i += 0.01
if ball.Parent:GetAttribute("CanUpdateLerp") == false or ball:GetAttribute("LerpID") ~= lerpid then con:Disconnect() return end
if (ball.Position - pos3).Magnitude < 3 then con:Disconnect() return end
local rayparams = RaycastParams.new()
rayparams.CollisionGroup = "ServerBall"
rayparams.IgnoreWater = true
local rayres = workspace:Raycast(ball.Position, ball.CFrame.LookVector * 3,rayparams ) or workspace:Raycast(char.HumanoidRootPart.Position, frontraycast, rayparams)
if rayres and rayres.Instance then
if rayres.Instance.Name == "Net" then
if not netcon then
netcon = run.RenderStepped:Connect(function()
if ball.Parent:GetAttribute("CanUpdateLerp")== false then netcon:Disconnect(); con:Disconnect() return end
if ball:GetAttribute("LerpID") ~= lerpid then netcon:Disconnect();con:Disconnect() return end
task.spawn(function()
task.wait(0.4)
if (Vector3.new(ball.Position.X, ball.Position.Y, 0) - Vector3.new(pos3.X, pos3.Y, 0) ).Magnitude < 3 then netcon:Disconnect(); con:Disconnect() return end
end)
print("clientnetcon")
if lv then
ball.CFrame =CFrame.lookAlong(Vector3.new(CFrame.new(quadbezier(i * truedt * multby, pos1, pos2, pos3)).p.X, CFrame.new(quadbezier(i * truedt * 60, pos1, pos2, pos3)).Y , rayres.Instance.Position.Z - lv.Z * 2), lv)
else
ball.CFrame = CFrame.new(quadbezier(i * truedt * multby, pos1, pos2, pos3).X, quadbezier(i * truedt * 60, pos1, pos2, pos3).Y, rayres.Instance.Position.Z)
end
end)
end
end
return
end
if not netcon then
if lv then
ball.CFrame =CFrame.lookAlong(CFrame.new(quadbezier(i * truedt * multby , pos1, pos2, pos3)).p, lv)
else
ball.CFrame = CFrame.new(quadbezier(i * truedt * multby, pos1, pos2, pos3))
end
end
end)
end
thank you for your help in advance