How can I shake the scene/camera upon impacts etc?

Hi,

I have recently started looking into vr game development with Unity. I already created XR origin including main camera, left and right hand controllers. I am using action based controller.

I want to know how I can create a function to shake camera or scene upon impacts etc. ? I know how to create random offsets but where should they be added? Should I add them to XR origin?

In case of VR, the camera is moving with headset right? should I add small random offset to position of headset when shake function is called? If yes how I can do that?

Hey @ab5050

First, I would advise caution on shaking the user camera during gameplay as this can induce motion sickness for most players.

In general these effects should be applied to the Camera Offset object in the scene (if wanting to include controllers in the shake) or create an additional offset between the Camera Offset and the Main Camera to act as the object you would move in this case with a script.

Again, we strongly discourage physically moving/shaking the camera, but if you are looking for ways to signal impact or hits or sudden changes, I would suggest using a Post Processing effect or you could even use the Vignette sample we recently shipped as a sample with XRI 2.1.0-pre.1, where you could shake the vignette or ‘vibrate’ the aperture size to create different visual effects or decrease the vignette size and change the color depending on the source of the change.

I hope this guidance helps. Let us know if you have any other questions.