Screen Shaking Problem

I have a script to make your camera shake the closer you get to a part, but the camera ends up turning sideways since it doesn’t try to stay centered.

I tried a couple of things, but nothing worked. Does anyone have any ideas how to fix this?

while task.wait() do

	if workspace:FindFirstChild:("Entity") then
		
		local intensity = 20
		local range = 120

		local dist = game.Players.LocalPlayer:DistanceFromCharacter(workspace.Entity.WorldPivot.Position)

		local cam = workspace.Camera
		
		local clamp = math.clamp(1 + (intensity - 0.1)*(1-(dist/range)), 0.1, intensity)
		
		cam.CFrame *= CFrame.Angles(math.random(1 - clamp, clamp) / 500, math.random(1 - clamp, clamp) / 500, math.random(1 - clamp, clamp) / 500)
	end
end
2 Likes

You could try storing an initial CFrame for the camera and then offsetting the camera CFrame based on that initial CFrame for the camera shake just to make sure the shake doesn’t differ too much from the original position.