I have a main menu inspired by Shinobi Life 2, but on higher fps the camera moves very quickly compared to 60fps. I don’t have much experience with delta time so i was hoping someone could help me understand where to apply it.
Video:
Code:
RenderStepped = RunService.RenderStepped:Connect(function(dt)
local CameraCF
local PartCF = MenuCams[scrollValue].CFrame
if not transition then
local Sine = math.sin(1 * os.clock()) / 45
local Cos = math.cos(1 * os.clock()) / 45
CameraCF = PartCF * CFrame.new(Cos, Sine, 0) * CFrame.Angles(Cos, Sine, Cos / 2)
else
local controlOffset = MathFunctions.offsetMidpointInCircle(startCF.Position, PartCF.Position, 40, 45)
local halfPoint = (startCF.Position + PartCF.Position) / 2
local controlPoint = Vector3.new(controlOffset.X, halfPoint.Y + 5, controlOffset.Z)
local newPos = Interpolation.QuadBezier(startCF.Position, controlPoint, PartCF.Position, t)
local x, y, z = PartCF:ToEulerAnglesXYZ()
CameraCF = CFrame.new(newPos) * CFrame.Angles(x, y, z)
local mag = (PartCF.Position - CameraCF.Position).Magnitude
if mag <= 0 then
transition = false
end
t += 1/45
end
Camera.CFrame = Camera.CFrame:Lerp(CameraCF, 0.03)
local vel = (Camera.CFrame.Position - lastCamPosition).Magnitude / dt
lastCamPosition = Camera.CFrame.Position
WindSFX.Volume = vel / 300
WindSFX.PlaybackSpeed = vel / (100 * rand)
calculateMotionBlur(vel)
calculateFOV(vel)
end)
The RenderStepped event fires every frame per second as mentioned in the roblox documentation about runservice, you usually use runservice with objects by a change in position or cframe with respect to time by constantly multiplying it with deltaTime every frame per second.
Yes I understand that I need to use delta time, I just don’t know what to apply it to. I’m mainly looking to fix the position. For that script I divided it by delta time because I was looking for the velocity. Velocity is distance / time. The issue i’m having is with the movement of the camera, I multiplied dt to the time value, and the positional value and neither worked correctly.
The value I replaced 0.1 with was 0.5 since the base was too small, are there segments of your code that shows the purpose of variable t and are you still dividing by dt? Only line that uses deltaTime is here
Never seen transitionDuration anywhere there, I was about to say either t += dt or apply deltaTime with the translated position based on whatever t is.
The way this was worded had me confused for some time