How to do a mild camera shake?

So recently, I posted another question in this category on rotating a CFrame without doing anything to the position, which I have now figured out was a mistake, as I was trying to make a fix for a solution (which probably isn’t the best), rather than find a better way of dealing with the root issue. (I did a XY problem)

So I’m making this one to sort out my real issue: I am trying to make a camera “shake” when the player fires a gun (the shake is not really a shake, more so a jerk).

The method I have been trying to use was TweenService, which pauses the camera’s position while the tween plays (very bad, because I’m using a first-person viewmodel that uses a Renderstepped function to position itself). In addition, trying to move the camera is very difficult, as the tween still tries to play, so this is not viable.

In addition, I tried using CFrame:Lerp(), which gives me the same problem that it gets really infuriating to move the camera, as the lerp keeps trying to position the camera to where you originally fired.

So, I ask you all, how do you make camera jerks and shakes? I would use Humanoid.CameraOffset, but I want the camera to rotate in any random direction, rather than move the camera to slightly different positions in a small amount of time.

This is the code I currently have. I think I may have to rewrite it and use a different solution.

local TweenService = game:GetService("TweenService")
local Info = TweenInfo.new(0.075, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, true, 0)
game.ReplicatedStorage.RemoteEvents.CameraShake.OnClientEvent:Connect(function(X, Y, Z)
	local Goal = {}

	Goal.CFrame = workspace.CurrentCamera.CFrame * CFrame.Angles(X, Y, Z)
	local Tween = TweenService:Create(workspace.CurrentCamera, Info, Goal)
	Tween:Play()
end)

I would gladly like help with this, please.
Thanks

(Also, if you saw my previous topic, I apologize for wasting your time and not telling you what I actually wanted to do)

Found some previous topics that may have what you are looking for:

Check the solution for the top one it seems to fit what you need most.


The shake works, but I can’t move my mouse while it’s happening which is what I’m trying to avoid (altered part of the script so it’s cameratype is still custom since scriptable doesn’t work in my context)

EZ Camera Shake does the same thing as well.
The last post on the second topic seems to work though, I’ll have to edit it slightly and see if it changes anything. Problem is that I’m not the sharpest at mathematics in lua, and there’s no documentation or comments on what any of that means.

So I’ve now tried implementing EZ Camera Shake again after carefully looking through the documentation, and it works now! I just have to link some events together.

1 Like