The script is inside a LocalScript…
I’m very slow at this, I assume everyone already knows of this and maybe someone knows of a better way to do this but I haven’t been active on studio due to obligations a lot. But any thoughts on this code? Anyone found a better alternative? I mean all you have to do is change the task.wait() in the loop to reduce the intensity and the math.random() values to change how far it rotates your screen per iteration.
repeat task.wait()
workspace.Camera.CFrame *= CFrame.Angles(math.rad(math.random(-2,2)), math.rad(math.random(-2,2)), 0)
until nil
You could bind to RenderStep and determine the rotation based on a function of the time difference within a sine/cosine function. It would probably ‘appear’ smoother to the user rather than rapidly jumping between frames.
(Needs some tuning, and can offset the t value per angle to induce more chaotic rotation)
Though this is just one of the many ways of doing it.
The reason i avoided the scriptable method is because i also had to account for a users capability to also control their camera as it was shaking at the same time
I only used that as a simple demonstration that I could whip up in studio quickly. It should be relatively simple to apply to a *=. The nature of sine is that it’s a repeating symmetrical function, so for each positive increment, there will eventually be an equal negative increment. It’ll just produce a smoother result than randomly adding increments.
local function ShakeCamera(shakeCf)
-- shakeCf: CFrame value that represents the offset to apply for shake effect.
-- Apply the effect:
camera.CFrame = camera.CFrame * shakeCf
end
-- Create CameraShaker instance:
local renderPriority = Enum.RenderPriority.Camera.Value + 1
local camShake = CameraShaker.new(renderPriority, ShakeCamera)
-- Start the instance:
camShake:Start()
-- Apply explosion shakes every 5 seconds:
while (true) do
wait(5)
camShake:Shake(CameraShaker.Presets.Explosion) -- You can change to whatever preset you'd like to use
end
Not complicated as it looks. For most of your cases, you’d only need to change stuff after camShake:Start().