Help With Screen Shake

Recently I’ve been thinking about how to make Screen Shake that’s the least disruptive as possible.

Camera Offset is fine, but looks quite harsh. CFrame.Angles() is too disruptive as it can move away from buttons etc.
To solve this I’ve been trying to figure out how to make something similar to this:

What I’ve Been Looking To Do:

So far I’ve realized that this effect only seems to work when camera type is set to ‘Scriptable’, which I can’t use as the player needs to be able to move. I’ve also tried setting type to scriptable, then back to custom in a loop which I decided not to do since it’s really bad practice.

Any help would be appreciated, thanks!

Try this:

delay(0,function()
	cam.CameraType = Enum.CameraType.Scriptable
	local original = cam.CFrame
	offset(cam.CFrame * CFrame.Angles(0,-0.02,0),0.05)
	wait(0.05)
	offset(cam.CFrame * CFrame.Angles(0,0.03,0),0.05)
	wait(0.05)
	offset(cam.CFrame * CFrame.Angles(0,-0.01,0),0.06)
	wait(0.06)
	offset(cam.CFrame * CFrame.Angles(0,0.02,0),0.07)
	wait(0.07)
	offset(cam.CFrame * CFrame.Angles(0,0.02,0),0.05)
	wait(0.05)
	offset(original,0.1)
	delay(0.1,function()
		cam.CameraType = Enum.CameraType.Custom
	end)
end)

Also I didn’t make this so credits to who made it.

I currently don’t have a function for ‘offset()’. It’s flagged as an unknown global, so the script does nothing.

have you looked into the tween service at all? set the camera type to ‘Scriptable’ and use the tweenservice to smoothly move the camera to where you want it to go. you can also set the move time and the easing style. i recommend you set the easing style to ‘Elastic’ for the best shaking effect.

It works great, except it isn’t locked to the player’s head, and getting it to head lock while shaking just makes it stutter or act like a fake lag effect. Thanks, though!

have you tried rotating the head with the tweenservice and just using a camerastepped loop to lock the camera to the cframe of the players head?

Please don’t use this code, it has so many wrong things with it.

Let’s start with the use of delay() here which is pointless if you’re setting the delay to 0, there are better alternatives to this like coroutine.wrap which creates a new thread instantly instead of waiting for 0.03 seconds like delay() does.

Secondly, you shouldn’t be writing offset(cam.CFrame * CFrame.Angles(0,-0.02,0),0.05) wait(0.05) like that multiple times inside a single function, instead they should be inside a for loop and use two different tables or a 2 dimensional array to save the wait() and Cframe.Angles values and call the values depending on how many times did the loop repeat.

Third, you didn’t even show or mention about the offset() function in the code you sent which leads me to the 4th point to the fact that you didn’t even make this code or tell who made this code and just posting his code and referencing him as “Also I didn’t make this so credits to who made it.”. If this isn’t your code and you don’t know who made it, don’t post it.

I don’t even have to mention the fact that you didn’t explain how does the code work or which idea in mind it was designed around with in your post because I seriously don’t think you know the answer to that yourself.

Try this.

1 Like

I’ve been using that up until now, but I only need it to rotate on one axis, as I usually have it work as a visualizer based on PlaybackLoudness. Again, thanks though!

Yup! Works perfectly. Thanks for that, I never thought to actually move the thing it locks to rather than the camera itself. I’m assuming it worked as the axis it needed to shake on is locked to the rotation of the character’s head.

I’d recommend using springs, rather than @TimesOfGrace’s solution:

Springs are so much more of an elegant solution, they’re useful for just about anything movement related (tweening, screen shake, etc.), I’d recommend for everyone to use them.

1 Like