How do i make EZ Camera Shake change the shake strength dependant of explosion distance

The title mostly says it all, How do i make EZ Camera Shake change the shake strength dependant of the distance of an explosion. Because i have no idea how!
The code i have now:

local CameraShaker = require(game.ReplicatedStorage.CameraShaker)
local camera = workspace.CurrentCamera

workspace.DescendantAdded:Connect(function(object)
	if object:IsA("Explosion") then
		local cameraPosition = camera.CFrame.Position
		local explosionPosition = object.Position
		local magnitude = (cameraPosition-explosionPosition).Magnitude

		local function ShakeCamera(shakeCf)
			camera.CFrame = camera.CFrame * shakeCf
		end

		local renderPriority = Enum.RenderPriority.Camera.Value
		local camShake = CameraShaker.new(renderPriority, ShakeCamera)

		camShake:Start()

		camShake:Shake(CameraShaker.Presets.Explosion)
	end
end)

Thanks for reading.

2 Likes
local CameraShaker = require(game:GetService("ReplicatedStorage").CameraShaker)
local camera = workspace.CurrentCamera

local THRESHOLD = 100 -- Max distance

-- Initialize shaker
local camShake = CameraShaker.new(Enum.RenderPriority.Camera.Value + 1, function(offset)
	camera.CFrame *= offset
end)

camShake:Start()

-- Listen for explosions
workspace.DescendantAdded:Connect(function(object)
	if object:IsA("Explosion") then
		local distance = (camera.CFrame.Position - object.Position).Magnitude
		if distance > THRESHOLD then
			return -- Not close enough!
		end
		
		local scale = 1 - (distance / THRESHOLD) -- Inversely proportional to distance
		local shake = CameraShaker.Presets.Explosion
		shake:SetScaleMagnitude(scale) -- Scale magnitude of preset
		camShake:Shake(shake)
	end
end)

I would also suggest looking into CollectionService as a much cheaper alternative to workspace.DescendantAdded.

This works perfectly! Also customizable.