I made a screen shaking script but the problem is that it turns the camera too far to the side and I want to keep the camera’s rotation in a certain area from where it started/where you turn your camera. I want it to turn your camera a lot, but you could still walk in a straight line without having to manually adjust the position of your camera. I will provide code if needed, but I think I could figure it out if presented with an idea.
Set limits for the maximum and minimum rotation of the camera. If shaking causes the camera to rotate, check that the new rotation is within these limits before applying it. (my guess on how to solve the problem)
My idea would be to store the camera’s original CFrame given this looks to be a cameratype of scripted.
Else again like what creatorimpossible said, set a limit and using deltatime or some other method of smoothing, -= or += the shake to the center
You could probably use a trigo function like sine to make this camera shake. They are structured like y = asin(bx)
, where b is the period, a is the amplitude and y is the result (angle to shake). The size of your shake is determined by an and the vigorousity of your shake is determined by b. Play around with different numbers until you get what you what
PS
You need to edit camera like this if you’re gonna use sine
cam.CFrame *= CFrame.Angles(math.rad(y),math.rad(y),0)