EZ Camera Shake ported to Roblox

very nice to see unity assets imported to roblox.

2 Likes

I am having an issue where this script:

function CameraShaker:ShakeOnce(magnitude, roughness, fadeInTime, fadeOutTime, posInfluence, rotInfluence)
	local shakeInstance = CameraShakeInstance.new(magnitude, roughness, fadeInTime, fadeOutTime)
	shakeInstance.PositionInfluence = (typeof(posInfluence) == "Vector3" and posInfluence or defaultPosInfluence)
	shakeInstance.RotationInfluence = (typeof(rotInfluence) == "Vector3" and rotInfluence or defaultRotInfluence)
	self._camShakeInstances[#self._camShakeInstances + 1] = shakeInstance --this line has the error
	return shakeInstance
end

returns the error “attempt to get length of a nil value” even though I used a cameraShaker.new() and a CameraShakeObject:Start() function in the camera shake wrapper module script:

local CameraShaker = require(script:WaitForChild("CameraShaker"))

local CurrentCamera = workspace.CurrentCamera

local CamShake = CameraShaker.new(Enum.RenderPriority.Camera.Value, function(shakeCFrame)
	CurrentCamera.CFrame *= shakeCFrame
end)

CamShake:Start()

Does anyone know how to solve this issue?

Nevermind, I solved it by changing the variable in the shaker wrapper module from the CameraShaker module to the camera shake object (CameraShaker.new() result)

I’m using this as part of a cutscene I’m making, so the camera is set to Scriptable. After the camera shakes, the camera’s cframe isn’t exactly where it originally was. Is there a way to counter this or would you just have to set the camera’s cframe again?

Is there a way to make the screen shake, but not offset your mouse position?

1 Like

Do you put the scripts into server script service? Also do you call it in a local or server script. Anyone know?

Anyway to have this only affect the camera on one axis?

You need to call this on the client because only the client has an active camera.

2 Likes

Sorry for reviving, but is there a way i can make this work with tweens?

Hello! I have been trying to make a little camera shake for my game; here is the script I use:

local camerashaker = require(game.Players.LocalPlayer.PlayerScripts:WaitForChild("CameraShaker"))

local player = game.Players.LocalPlayer

repeat task.wait() until game:IsLoaded()

local char = player.Character
local hum = char:WaitForChild("Humanoid")

local camera = game.Workspace.CurrentCamera

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

camShake:Start()

local iswalking = false
local previous = true

while task.wait() do
	if hum.MoveDirection.Magnitude > 0 then
		iswalking = true
	else
		iswalking = false
	end
	
	if previous ~= iswalking then
		if iswalking == true then
			print("walk")
			camShake:StopSustained(0)
			camShake:ShakeSustain(camerashaker.Presets.Earthquake)
		end
		if iswalking == false then
			print("nowalk")
			camShake:StopSustained(0)
			camShake:ShakeSustain(camerashaker.Presets.HandheldCamera)
		end
	end
	
	previous = iswalking
end

Whenever I run it, it prints normally, however the camera shake intensifies a whole lot the longer I wait in a certain mode. After 30 seconds on the HandheldCamera, it does 360s and 180s. I don’t know if this is intentional, and if it is, how to fix it. Any help appreciated!

1 Like

Earthquake & Handheld Camera both have heavy like weight on the shake. If you go within the module and find a script that says presets you can choose the one you like which you could also modify. I suggest you dont use camera shakes for camera bobbing search up some videos on youtube for camera bobbing.

To anyone still looking for a fix to the violent shake problem, the issue seems to be fixed by adding a math.min on lines 72 and 79 of the CameraShakeInstance module. Hope this helps.

2 Likes

guy, my cam shake script on local side sometime causes game crashing without any error message its happens in both studio and roblox, here’s the code

				local cam = workspace.Camera
				local CameraShaker = require(rs.Modules.CameraShaker)
				local camShake = CameraShaker.new(Enum.RenderPriority.Camera.Value, function(shakeCf)
					cam.CFrame = cam.CFrame * shakeCf
				end)
				camShake:Start()

				-- Explosion shake:
				local shakeInstance = camShake:ShakeSustain(CameraShaker.Presets.Explosion) -- You can check out the presets by going to your module and finding a child called "CameraShakePresets"
				shakeInstance:StartFadeOut(1)

is there anyway to fix this?

This is honestly super cool and easy to use! I wanted to play around with it so I made a little view bobbing script that triggers the shake while walking. However, I wasn’t sure how to make a custom preset so I just edited the Rough Driving one.

2 Likes

(I didn’t know the music was on. I was listening to the Roblox copyright replacement music :sob:)

You can change the rotation and position influence with the custom shake methods

local Camera = workspace.CurrentCamera
local Shaker = CameraShaker.new(Enum.RenderPriority.Camera.Value+1, function(ShakeCF)
	Camera.CFrame *= ShakeCF
end)
Shaker:Start()
Shaker:ShakeOnce(1, 1, 1, 1, Vector3.zero, Vector3.new(1,1,1)) -- Magnitude, Roughness, fadein and fadeout time and the last 2 Vector3 values are position influence and rotation influence
Shaker:StartShake(1, 1, 1, Vector3.new(0.5,0.5,0.5), Vector3.new(1,1,1)) -- same thing but for sustained shakes (like earthquakes) you can also just copy values off the presets and edit the influence
1 Like

sup this is a cool module that i’ve been using for 4 years now really helps me with camera stuff

I want to share this fix for all who has fps problem.
The problem is if we change the fps, the camera shook more

My friend asked to sleitnick for fps fix and he replied to us.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")

local CameraShaker = require(ReplicatedStorage.CameraShaker)
local CAMERA = workspace.CurrentCamera

-- Copied from example. Just added prevCamCf
local prevCamCf = CAMERA.CFrame
local camShake = CameraShaker.new(Enum.RenderPriority.Camera.Value, function(shakeCf)
    prevCamCf = CAMERA.CFrame
    CAMERA.CFrame = CAMERA.CFrame * shakeCf
end)

-- The fix:
-- Reset the camera on the first RenderPriority, before cam scripts run:
RunService:BindToRenderStep("ResetCF", Enum.RenderPriority.First.Value, function(dt)
    CAMERA.CFrame = prevCamCf
end)

camShake:Start()
camShake:ShakeSustain(CameraShaker.Presets.Bump)

This method can be useable in this module and current latest shake module
Thanks to sleitnick for helping us! :grin:

2 Likes

If you want, you could also use RunService.Heartbeat to reset the CFrame, since that runs after all the rendering is done too. Either work!

2 Likes

Is that will make lag? SLEOW grigjrtxzassad