Problems with EZ Camera Shake

I’ve been trying to make it so that when a person is damaged from combat, it shakes the camera using the bump preset included in the presets.
I cannot seem to make it work as it only seems to happen in the camera of the person who attacked instead of being damaged.
I have tried to implement it in the Damager remote script in serverscriptservice and on the actual combat script in starterpack.

EnemyHum:TakeDamage(Damage)
	
local camera = workspace.CurrentCamera
	
local CameraShaker = require(game:GetService('ReplicatedStorage').CameraShaker)
local camShake = CameraShaker.new(Enum.RenderPriority.Camera.Value, function(shakeCFrame)
	camera.CFrame = camera.CFrame * shakeCFrame
end)
	
camShake:Start()
camShake:Shake(CameraShaker.Presets.Bump)

Maybe you could try adding a camera shaker to the attackee, but just whenever their health changes, using the Humanoid.HealthChanged event:

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

local humanoid = -- humanoid's health to monitor

local camShake = CameraShaker.new(...)
camShake:Start()

local currHealth = humanoid.Health

humanoid.HealthChanged:Connect(function(newHealth)
    if newHealth < currHealth then
        camShake:Shake(...)
    end
    
    currHealth = newHealth
end)

You should obviously replace the (...)s with what you had from your previous code.

3 Likes

Thank you! This really helped me out! However, if they take damage every second or less than a second, wouldn’t the camera shake be constant and neverending?

Unless you added a debounce to prevent continuous shaking, yes:

-- pseudocode!

local debounce = true
HealthChanged:Connect(function(...)
    if debounce then
        debounce = false
        -- do stuff here
        wait(2)
        debounce = true
    end
end)

Although this would lead to unrealistic shaking if you’re hit right before the debounce ends.
The better alternative is just making the “Bump” smaller or shorter, or make the amount of damage received, currHealth - newHealth, affect how long or violent the shake is.

1 Like

Ahh thanks, you have given me more ideas!

1 Like

wait sorry but i don’t understand how to stop the issue, i have the same problem.