Has anyone out there made a screen shake effect for the camera and know the best way to implement it? I want this effect for something like an earthquake, a large explosion, or a heavy impact. Ideas?
I accomplished this in a very easy way. If you have access to a 3D Animation app, just animated an object (a simple cube, for instance) shaking and moving a bit randomly. In unity, make the camera a child of the object you animated and turn off the renderer. Whenever you want a camera shake, just play the animation.
I'm using a quite simple approach. I linked the main camera to an empty game object and if wanted to shake the camera, I set in each update a random local position of the attached camera within a unit sphere:
So it could look like this (semi pseudo code):
(all off head, have the complete function at home if you want it)
That function then shakes the camera locally around in each frame and decreases over time. So if you want to shake it, simply set "shake" to 1.0 or 2.0 or something like that and it starts to shake. I use the effect in my new "Decane intro" for all my games when the car crashes into my Decane logo. See the intro here:
Latest release: RC Mini Racers.