FPS lerp dependency question

Hey! Lately I have been trying to create my own first person camera system using RunService, CFrames and Lerps. During my Roblox Development, I’ve made 2 camera systems. Both were very FPS dependent and I’m trying to learn how to fix that.

What the question is really, which things do I use DeltaTime with?

Here’s something I made:

local RunService = game:GetService("RunService")

local Part = workspace:WaitForChild("Part")

local LerpAlphaValue = .1

RunService.RenderStepped:Connect(function(DeltaTime)
	local Target = Part.CFrame * CFrame.new(0, .1, 0)
	
	Part.CFrame = Part.CFrame:Lerp(Target, 1 - LerpAlphaValue ^ DeltaTime)
end)

(Lerp dependency issue fix, if you are curious: Frame rate independent lerp? - #18 by EmesOfficial)

So, from what I have tested, this runs finely and doesn’t have any FPS dependency issues. However, if I do

local Target = Part.CFrame * CFrame.new(0, 10 * DeltaTime, 0)

With the lerp calculation, the part goes faster on lower FPS, and slower on higher FPS.

I really really do not know where I should use DeltaTime, like if I should do it like that first example in the lerp, or if I just multiply DeltaTime with the desired target I want as the second example. I have tried searching for similar questions but none were helpful or at least for my situation

Thanks in advance!

Try doing, math.clamp(Alpha * DeltaTime * 60, 0.008, 1) or 1 - math.exp(-Speed * DeltaTime)

First one is simpler, while the second one is a tad bit more complicated, although both has the same purpose… and note on the second calculation, it doesn’t use traditional alpha, so might be tricky to use

Just read the whole post :sweat_smile:, anyways here are some simple answers

  1. DeltaTime helps keep things like Health Regen consistent, Just do HealthGenerationRate * DeltaTime to get how much to add… Since DeltaTime is in milliseconds, the rate is per second. Without it, the script might overshoot… (since most loops is also FPS dependent) so you use it for accurate per-second stuff

  2. Lerp or Value * DeltaTime? It depends, if you want to move a part to a SPECIFIC CFrame, then you use Lerp, but if it’s something like a bullet where there’s no target, and it just continues moving, then you use Value * DeltaTime

1 Like

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