-
What do you want to achieve?
I need to make the player camera move consistently when walking -
What is the issue?
I have made camera movement function that basically just moves the camera around. If I run the game at 60 fps, everything seems fine. However, if I run it at 240 fps, then the movement will become more intense. I’m pretty sure to solve this problem, I’ll need to use delta time but I don’t know how to implement it in my code. -
What solutions have you tried so far?
As I mentioned earlier, I have tried using delta time to multiply my values but they have all ended in weird results. I have also looked everywhere but I cant seem to find any answers online. Here is a video describing the issue/
Here is the code. The function is being run in a RenderStepped event.
local function SwayViewModel(deltaTime : number)
local tick = tick()
local cameraCFrame : CFrame = CFrame.new()
local moveX, moveY, moveZ = 0, 0, 0
if IsPlayerMoving() then
moveX = viewModelSwaySettings.amplitudeX * math.cos(tick * viewModelSwaySettings.speedX * math.pi)
moveY = viewModelSwaySettings.amplitudeY * math.sin(tick * viewModelSwaySettings.speedY * math.pi * 2)
moveZ = viewModelSwaySettings.amplitudeZ * math.cos(tick * 0.5 * math.pi * 4)
cameraCFrame = CFrame.new(moveX * 5, moveY * 5, moveZ * 2, math.rad(moveZ), 0, math.rad(moveX * 5), 1)
end
camera.CFrame = camera.CFrame:Lerp(camera.CFrame * cameraCFrame, 1)
end