The problem is whenever I move around in a small circular motion and then moving normally when the bounceTime is close to tau (2*pi), the camera becomes very bouncy for a brief moment before returning back to a normal frequency.
local tau = 2 * math.pi
local maxCameraSpeed = 100
local maxAmplitude = 0.3
local function Lerp(start, goal, t)
return start + (goal - start) * t
end
local function OnCharacterAdded(character)
local isMoving = false
local bounceTime = 0
local cameraSpeed = 0
local amplitude = 0
local currentCameraSpeed = 0
local currentAmplitude = 0
local humanoid = character:WaitForChild("Humanoid")
humanoid.Running:Connect(function(speed)
isMoving = speed > 0
cameraSpeed = speed * 1.5
amplitude = speed * 0.02
end)
connection = RunService.PreRender:Connect(function(delta)
bounceTime = (bounceTime + delta) % tau
currentCameraSpeed = math.min(Lerp(currentCameraSpeed, cameraSpeed, delta), maxCameraSpeed)
currentAmplitude = math.min(Lerp(currentAmplitude, amplitude, delta), maxAmplitude)
camera.CFrame += Vector3.new(0, math.sin(bounceTime * currentCameraSpeed) * currentAmplitude, 0)
end)
end