Smooth Camera Shaking

I have a decent camera shaking script but I want it to be slower and smoother. I thought of using tweens but you can’t move you camera, and im not sure how to use CFrame:Lerp(). Does anyone know a solution to this?

here’s my script:

local CFX,CFY,CFZ

workspace.SpawnedEntities.ChildAdded:Connect(function()
	local A175 = workspace.SpawnedEntities:FindFirstChild("A-175")
	if A175 then
		while task.wait(.02) do
			if workspace.SpawnedEntities:FindFirstChild("A-175") then
				local intensity = 15
				local range = 175

				local dist = game.Players.LocalPlayer:DistanceFromCharacter(workspace.SpawnedEntities:FindFirstChild("A-175").WorldPivot.Position)

				local cam = workspace.Camera

				local clamp = math.clamp(1 + (intensity - 0.1)*(1-(dist/range)), 0.1, intensity)

				CFX,CFY,CFZ = math.random(1 - clamp, clamp) / 1000, math.random(1 - clamp, clamp) / 1000, math.random(1 - clamp, clamp) / 1000

				cam.CFrame *= CFrame.Angles(CFX,CFY,CFZ) -- here's what I want to change
			else
				break
			end
		end
	end
end)
2 Likes

Hey, sorry I did not test It but I think this might work okay or need a bit of fix. hope It helps:

local function shakeCamera(targetCFrame, intensity, duration)
    local startTime = tick()
    local cam = workspace.CurrentCamera
    local originalCFrame = cam.CFrame

    while tick() - startTime < duration do
        local elapsed = tick() - startTime
        local alpha = elapsed / duration

        -- Random offset
        local offsetX, offsetY, offsetZ = math.random() - 0.5, math.random() - 0.5, math.random() - 0.5
        local shakeCFrame = CFrame.new(offsetX * intensity, offsetY * intensity, offsetZ * intensity)

        -- Interpolating between the original and the shake CFrame
        cam.CFrame = originalCFrame:Lerp(originalCFrame * shakeCFrame, alpha)

        task.wait()
    end

    -- Reset to original CFrame
    cam.CFrame = originalCFrame
end

workspace.SpawnedEntities.ChildAdded:Connect(function()
    local A175 = workspace.SpawnedEntities:FindFirstChild("A-175")
    if A175 then
        local dist = game.Players.LocalPlayer:DistanceFromCharacter(A175.WorldPivot.Position)
        local intensity = 0.5 -- Adjust the intensity as needed
        local range = 175
        local clamp = math.clamp(1 + (intensity - 0.1)*(1-(dist/range)), 0.1, intensity)

        shakeCamera(A175.CFrame, clamp, 2) -- Adjust the duration as needed
    end
end)

It doesn’t shake the camera and you can turn anymore… I guess lerping isn’t the way to go

Have you tried using springs? It is a simple animation module

Attempted to remake that entity.
Heres my design.


Good shaking though!