I am implementing a rudimentary camera shaking script as follows.
ShakePlayerCamera.OnClientEvent:Connect(function(Strength) RelativeStrength = math.clamp(1, 0, RelativeStrength + Strength) end) game:GetService("RunService").RenderStepped:Connect(function(dt) if RelativeStrength > 0 then local rX = Rnd:NextNumber(-1, 1) * RelativeStrength / 10 local rY = Rnd:NextNumber(-1, 1) * RelativeStrength / 10 local rZ = Rnd:NextNumber(-1, 1) * RelativeStrength / 10 workspace.CurrentCamera.CFrame = workspace.CurrentCamera.CFrame * CFrame.fromOrientation(rX, rY, rZ) end RelativeStrength *= 0.975 end)
The idea is that whenever the server fires
ShakePlayerCamera with the
Strength the parameter, the camera begins to shake, quickly losing its shake intensity until it is no longer shaking. I am using MaximumADHD’s Realism module, so the camera easily resets whenever the player is out and about.
The issue arises whenever I lock the camera to a specific
CFrame (for example, think hiding in a locker and setting the camera’s
CFrame to look out the locker holes) and then attempt to shake the camera. When I shake the camera then, as predicted, the camera shakes but does not reset to its original position, instead staying at an angle.
I could solve this by storing the
CFrame of the locked position and just set the camera’s
CFrame to a rotated version of that, but I feel like there is a better alternative. Is there a function or method that doesn’t involve me having to pull the
CFrame from an extraneous source in order to keep the