ScreenShake effect?

Hi im tunnells im wondering how you could make a screenshaking effect Like, If a rocket Hit the ground how could i use a script to start the screenshaking.

1 Like
delay(0,function()
	cam.CameraType = Enum.CameraType.Scriptable
	local original = cam.CFrame
	offset(cam.CFrame * CFrame.Angles(0,-0.02,0),0.05)
	wait(0.05)
	offset(cam.CFrame * CFrame.Angles(0,0.03,0),0.05)
	wait(0.05)
	offset(cam.CFrame * CFrame.Angles(0,-0.01,0),0.06)
	wait(0.06)
	offset(cam.CFrame * CFrame.Angles(0,0.02,0),0.07)
	wait(0.07)
	offset(cam.CFrame * CFrame.Angles(0,0.02,0),0.05)
	wait(0.05)
	offset(original,0.1)
	delay(0.1,function()
		cam.CameraType = Enum.CameraType.Custom
	end)
end)

This one here uses the camera offset to create the effect you need. You can adjust the Angles and offset if you want a more shake effect.

8 Likes

EZ Camera Shake ported to Roblox is a really good module for this. You can create your own custom shakes or use presets that are included in the module.

6 Likes

That’s a VERY bad way of doing it, a for loop would be much better.

Here’s a basic local script I use for screen shakes.

local character = player.Character
local oldOffset = character.Humanoid.CameraOffset
	
for i = 0, shakeIntensity * 10 do -- use a value between 0 and 3 (shake intensity), you can also increase the iterations.
	local offset = Vector3.new(math.random(-1,1), math.random(-1,1), math.random(-1,1))
	character.Humanoid.CameraOffset = character.Humanoid.CameraOffset:Lerp(offset, shakeIntensity * 0.25)
	RunService.Heartbeat:Wait() -- defined somewhere else in the script
end
character.Humanoid.CameraOffset = oldOffset

It looks like this.

15 Likes

I’d personally recommend making this a function, as that way, you can easily feed it some parameters. For example:

ShakeCamera(intensity, duration) --really, anything you need/want

Plus, it avoids copy-pasting the same code in case you have to use it in more than one place, which is often bad practice.

2 Likes

Yeah, that’s kinda what I do, as the code used there is in a fire client event.

CombatRE.Combat.CameraShake:FireClient(player, player, 1.5) -- shake intensity
1 Like

We need the full script please give us the full script

1 Like