Camera Shake Using Random Rotation

Is there a way to achieve a camera shake but by using only the rotation of the camera?

Sure - it’s very seldom that there’s actually ‘no way’ to do something :wink:

As for how to do it, that will depend somewhat on what sort of effect you want. Here’s one method you might try though (untested):

  1. Attach the camera to an object that’s a child of another object and set its transform to identity.

  2. Each update, generate a random unity vector in the XY plane and scale it by the current ‘shake magnitude’ (presumably the ‘shake magnitude’ will decrease over time as the effect progresses).

  3. Add this vector to the cardinal z axis (Vector3.forward).

  4. Use Quaternion.LookRotation() to set the local rotation of the camera, with the vector computed in steps 2 and 3 as the input.

Note that that’s just one way to do it; there are plenty of other methods you could use as well (both in terms of modifying the orientation and generating the ‘noise’ that functions as the input).

I have a smooth script (average out the last 40 positions of the camera) script I’ve modded to have screen shaking. Along with the regular 40 averages, I have an alternate set that I add extreme values to whenever I want shaking. A cool effect of this is the shaking is very fast initially, than becomes very smooth towards the end (as the highest longest values no longer have ‘competition’).

Jesse’s also works well, would be much easier to make :stuck_out_tongue:

Generally you will need to remember the camera’s data, else shaking will leave it in horrid places and just be a headache. Smoothing has the side effect of taking care of itself.

This entry in the Explosivo! contest utilises camera shake; you may be able to have a look at the code and derive your own from it.