EZ Camera Shake ported to Roblox

The Unity Asset Store has a free asset called EZ Camera Shake, which I have ported to Roblox.

Module:

GitHub repository:

The original author of the Unity3D asset, Road Turtle Games, gave me written permission via email to make and open-source this port to Roblox. I contacted the developer since there was no licensing information available for the Unity3D asset.

Example of the module using the Explosion preset:

Example code:

local camShake = CameraShaker.new(Enum.RenderPriority.Camera.Value, function(shakeCf)
	camera.CFrame = camera.CFrame * shakeCf
end)

camShake:Start()

-- Explosion shake:
camShake:Shake(CameraShaker.Presets.Explosion)
507 Likes
How can I make my screen shake?
Camera Shake like an earthquake while still staring at the player
How to make camera shake on touch?
How do you make your camera revert after shaking it?
Issue with Camera Rotating Screenshake
How to use EZ Camera Shake?
Crazyman32 Camera Shaker, help needed
Smooth Camera Shakes
Character attack moves, animations and effects: Feedback wanted!
Help with FastCast Recoil + Spring
Camera shake for binoculars or scope
How to monetize a game and get a least 1k people playing?
How to code camera shaker
Make a camera shake ONLY in a certain area
How do you add a camera shake effect?
Screen shake effect when touch of a part
ScreenShake effect?
How would I recreate this kind of screen shake?
So im trying to make a Screen Shake
How to make the camera shake on touch
Screen Shake with Magnitude?
¿How to shake a screen? 2d platform
Weather System [Open-Sourced]
Combat Testing Information
Gear Remastered: Rainbow Magic Carpet
Simple camera shake that I can use for my guns?
Simple camera shake that I can use for my guns?
How too create a gentle camera shake?
CameraUtil - Your new tool for simple camera manipulation! (OPEN-SOURCED)
Is other way to do a screen shake without CameraOffset?
Blackout Credits
Why wont this camera shake work?
Lava Eruption Vfx
Make a camera shaking
Can Anyone Help me make my script Smoother?
Detect Workspace Explosions?
Help creating explosions
How can I make an camera shake when taking damage?
Feudal Japan | Credits
How can I make a camera shake effect
Combat Warriors Information
Need help with camera animations
Monsters of Etheria Attributions
How to make the snake camera
[UPDATE] Introducing EZCamera!
VVG's "Survive a Plane Crash" Credits
Roblox Titanic Credits
Sinking Ship: Roblox Britannic Credits
How does Phantom forces do arm view bobbing?
Earthquake/Screen Shake Effect
Help With Screen Shake
Having Probelms with making Camera Effect
How is this giant door cutscene?
MainMenu Smooth Tweening(Breathing Effect)
Rex Framework | Designed for beginners to intermediate developers
Make a camera shake ONLY in a certain area

they should always list the licensing if there is,correct me if i’m wrong.

13 Likes

What’s the algorithm for shaking? Some kind of spring? Looks really cool, I hope you can release it.

19 Likes

The developer already got back to me and gave me the all-good to do this! Pretty sweet.

23 Likes

Yes! that’s great!

4 Likes

Interestingly, it’s using perlin noise!

18 Likes

Updated original post with a link to the module. Let me know if anyone runs into any problems with it.

9 Likes

Just wondering, what would playerCFrame in your example be set to? Is it possible to play these shakes over the default camera and still have it rotate regularly somehow?

Also, I see a method for starting the shake which has a fade-in time, but I don’t see a method for fading out a shake, only an abrupt :Stop() method. How would I fade-out a shake over some time instead of stopping it abruptly, or does this module not provide for that yet?

4 Likes

playerCFrame is just an example of whatever camera logic you might already have. The idea is that you just multiply the existing CFrame of the camera to the shake CFrame. For instance, you could just set a higher render priority and set the loop to only manipulate the Camera’s CFrame directly, assuming another loop has already set it:

local camShake = CameraShaker.new(Enum.RenderPriority.Last.Value, function(shakeCf)
	camera.CFrame = camera.CFrame * shakeCf
end)
camShake:Start()

To your other question: It’s kinda weird. The “state” of an individual shake instance is determined in the CameraShakeInstance:GetState() method. If that state returns Inactive, then the CameraShaker object will automatically delete it from the update table.

But that still begs the question…how do you stop the shake instance? As far as I can tell, the way you stop it is by calling CameraShakeInstance:StartFadeOut(fadeOutTime). It’s unfortunate that you have to pass a fadeOutTime parameter, as that should already be set from the constructor, so I am going to make a change to make it an optional parameter.

When you call StartFadeOut, it runs the appropriate fading math on the update loop, and thus ends up changing the calculated state to Inactive eventually.

8 Likes

Update: I confirmed that calling StartFadeOut is how you stop a sustained shake. However, the existing code did not allow for a preset shake to be sustained, so I added another ShakeSustain method. Also, based on the logic of the code, StartFadeOut must supply a fade out value, as sustained shakes overwrite the original fade out value to 0.

Example using the Earthquake preset:

local earthquakeShake = nil
local function RightClicked()
	if (earthquakeShake) then
		earthquakeShake:StartFadeOut(10)
		earthquakeShake = nil
	else
		earthquakeShake = camShake:ShakeSustain(camShake.Presets.Earthquake)
	end
end
5 Likes

That’s so awesome. There are so many uses for this… pulls out 8th soda, opens Studio

15 Likes

Woooooow. Very very neat. It would be cool to see more games utilizing the camera in this sort of way, it really adds an extra layer of depth to the game.

1 Like

I’m getting some serious nostalgia watching a crazyman32 video again where he shows the script contents before he presses play…

21 Likes

Is it intentional that on line 130 in the CameraShaker module you have:

rotAddShake = rotAddShake + (c:UpdateShake(dt) * c.PositionInfluence)

instead of:

rotAddShake = rotAddShake + (c:UpdateShake(dt) * c.RotationInfluence)

?

Edit Also in the camera shake instance module, why are you subtracting 0.5 from the noise’s for x,y, and z? The roblox wiki says that they already return values between -1 and 1 (lines 55-57)

3 Likes

Good catch! I translated the code from C# to Lua very quickly, so weird errors like that were bound to happen.

As for the noise, I also failed to look into the difference between Unity’s PerlinNoise function and Roblox’s noise function. In Unity, it returns between 0 and 1, and I didn’t notice that until now. The obvious fix would be to add 1 to the result, and then divide it by 2, thus giving the same 0 - 0.5 range: [(1 + noise) / 2)] However, I actually want a -0.5 - 0.5 range, thus I am changing it to simply multiply by 0.5 instead of subtract.

Thanks for posting about that. Those fixes are now published.

9 Likes

YAY this saves me so much work

thank you!

3 Likes

Seems like I cannot run two shakes at once, one of them being a constant shake and the other one a single shake.

3 Likes

Gross, that’s annoying. Overlaying should definitely be supported! I’ll try to set aside some time this weekend and see if I can get that working.

6 Likes

I know this is sort of off topic, but what colours do you use for your script editor

1 Like

What are we supposed to put this modulescript to?

2 Likes