EZ Camera Shake ported to Roblox

With Roblox’s faster Lua VM, it’s unnecessary to cache table access like local V3 = Vector3.new (doing so now incurs a minor performance penalty).

2 Likes

Since the code is on Github, you can submit a PR to fix it if you’d like. I wouldn’t recommend spending time on it if you have better things to be doing though – the performance difference is likely very minimal.

2 Likes

I have a plane taking off cutscene, and I’d like to make this as realistic as possible by including a minor shake effect. However, since the CFrame is already set every frame, will this mess it up? If so, how would I get around it?

1 Like

Sorry for the necrobump but is there a way to make it so the camera shake is consistent with FPS? In the GIF below, when my FPS is ~400, the camera shake moves the screen a lot more while when my FPS is 30, it barely moves the screen.

https://gyazo.com/6b68b44fe8c2bdd19cd6189c9133f0ef

8 Likes

That’s pretty strange, CameraShaker:Update scales based on time since last frame. Is the same problem present comparing say 30 fps to 60fps? I have never heard of having over 60 FPS in roblox forever, that sounds like something weird.

I believe the problem is still present even when comparing the shakes between 30fps and 60fps.

I’m using an fps unlocker to get my fps over 60.

This doesn’t work. It doesn’t do the shake when player joins.

Also the example code justs makes alot of undefined variables, a better example would be good please :slight_smile:

It does work. I use this in just about all my projects. The only undefined item in the example is the actual ‘require’ of the module:

local CameraShaker = require(theCamShakeModule)

If you’re having trouble doing something specifically with it, please let me know and I can try to help.

2 Likes

I did that. I put it in rep storage.

Here is the script that I am tryna do this:

local camera = workspace.CurrentCamera
	
local CameraShaker = require(game:GetService('ReplicatedStorage').CameraShaker)
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)
2 Likes

It does work, and you just stated your exact problem.

local camera = workspace.CurrentCamera
	
local CameraShaker = require(game:GetService('ReplicatedStorage'):WaitForChild("CameraShaker"));
local camShake = CameraShaker.new(Enum.RenderPriority.Camera.Value, function(shakeCf)
	camera.CFrame = camera.CFrame * shakeCf
end)

camShake:Start()

-- Explosion shake:
wait(5);
camShake:Shake(CameraShaker.Presets.Explosion)

I slightly modified your code (wait(5)) and it works perfectly. You have it running too quickly.

4 Likes

Doesn’t work still! Here is a screenshot.

PLS

local camera = workspace.CurrentCamera
	
local CameraShaker = require(game:GetService('ReplicatedStorage'):WaitForChild("CameraShaker"));
local camShake = CameraShaker.new(Enum.RenderPriority.Camera.Value, function(shakeCf)
	camera.CFrame = camera.CFrame * shakeCf
end)

camShake:Start()

-- Explosion shake:
wait(10);
camShake:Shake(CameraShaker.Presets.Explosion)

Should I use pcall?

2 Likes

Wait, are you using a script, and not a local script?

1 Like

I am using a script as seen in the screenshot 2 messages up.

local camera = workspace.CurrentCamera

local CameraShaker = require(game:GetService('ReplicatedStorage'):WaitForChild("CameraShaker"));

local camShake = CameraShaker.new(Enum.RenderPriority.Camera.Value, function(shakeCf)

camera.CFrame = camera.CFrame * shakeCf

end)

camShake:Start()

-- Explosion shake:

wait(10);

local didWork, didntWork = pcall(function()

camShake:Shake(CameraShaker.Presets.Explosion)

end)

if didntWork then

print(didntWork)

end```

I used pcall and nothing happened, success then? Still didn't shake though
2 Likes

There’s your problem. How do you expect this to work with a script? This needs to be running in a local script. Before using this module, or any other modules, you might want to first learn the difference between a local and server script, and also before claiming that this module doesn’t work.

8 Likes

Oh. Ok. I know what the difference is lol.

Apparently not, why would you try and use a server script with this…?

7 Likes

It works! Horray! Sorry I thought it had to be used in a server script. It’s a bit slow the shake though.

4 Likes

You can take a look at the API for different ways to shake the camera, faster or slower. GitHub - Sleitnick/RbxCameraShaker: Camera shake effects for Roblox games

6 Likes

Thanks so much :slight_smile:

#VeryHelpful

2 Likes