Unity Community

Results 1 to 6 of 6

  1. Location

    Screen Shake Effect

    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?
    Web developer at your service. Current project: Annuity

  2. Location
    Jacksonville, AL
    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.


  3. Volunteer Moderator

    Re: Screen Shake Effect

    This project has a camera shake routine in it. Using code instead of an animation means you can dynamically change the intensity and so on.


  4. Location
    Thanks guys, two unique solutions! I would prefer code if it produced an effect to my liking. I'll have to test this out.
    Web developer at your service. Current project: Annuity

  5. Location
    Hamburg, Germany
    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):

    1. var camera : Camera; // set this via inspector
    2. var shake : float = 0;
    3. var shakeAmount : float = 0.7;
    4. var decreaseFactor : float = 1.0;
    6. function Update() {
    7.   if (shake > 0) {
    8.     Camera.transform.localPosition = Random.insideUnitSphere * shakeAmount;
    9.     shake -= Time.deltaTime * decreaseFactor;
    11.   } else {
    12.     shake = 0.0;
    13.   }
    14. }

    (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:


    - Martin
    Latest release: RC Mini Racers.

  6. Posts
    Thanks Martin, very simple solution and it's working great!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts