How to do screenshake without influencing the transform of the camera?

I want to get a screen-shake effect on my main camera, It is a first person camera and it is set up to follow the ‘player’ object, is there another way to do screen-shake, without screwing with the camera’s transform? because if I do that the player basically has to sit and wait for the screen-shake to be over, they can’t move the camera while it is being shaken because the script I am using basically takes control of the camera’s transform and plays with the values. This is very jarring and obviously not ideal.

Does anyone have any ideas, or any methods that they have used in their own games for screen shake as an effect for a moving camera controlled by the player?

Well, I think the best way is to actually influence the transform of the camera.

There would be 2 ways that I can think of atm of how you can achieve this. In these examples, I will call your script that takes over the transform of the camera “CameraController”.

1:

  • Edit your CameraController in a way that it works with 2 Vector3’s instead of the one of the Transform.
  • One of the Vector3’s represends what used to be transfrom.position.
  • The other one represents the screen shake offset.
  • By combining these two values you should get a correct position that can be used by the camera transfrom.

2: (The easiest one)

  • Make the camera a child of an empty
    gameobject.
  • Move your CameraController script from your camera to this empty gameobject.
  • Add a Screenshake script to the camera and let it change the localposition of the transform.

This way you CameraController can still control the transfrom without problems, as the ScreenShake script will never influence the Transfrom of its parent. Another advantage is that you can simply work with localPosition and localRotation, which means you can work with an offset to the direction that the CameraController is facing.

You could write an image effect that jitters the screen. Not essentially good for performance but might be worth a try.

You can copy, say the grayscale image effect and add values like a float offset.
You can add that offset to the u/v coordinates while reading the color info.
Then in your image effect script you get a random value for your offset and set it in the image effect material.