Unity Community


Results 1 to 10 of 10

Thread: camera shake


  1. Posts
    364

    camera shake

    hi i m very new to unity

    i would like to know how would i go about coding a camera shake script to make the effect that the ground has shaken such as when a grenade explodes.

    any help would be good


  2. Posts
    482

    Re: camera shake

    Quote Originally Posted by jin76
    hi i m very new to unity

    i would like to know how would i go about coding a camera shake script to make the effect that the ground has shaken such as when a grenade explodes.

    any help would be good
    You could either use math to animate the shake, or a short random wobbly/shaking animation attached to the camera and made to trigger on certain events.


  3. Location
    Sydney, Australia
    Posts
    1,894
    iTween has a sweet camera shake built in. One line of code.


  4. Location
    Baltimore, Maryland, United States
    Posts
    674
    If you plan on using iTween put your camera in a "holder" object since iTween will completely override all position values while its Shake() is running on the camera. Apply your iTween.ShakePosition() or iTween.ShakeRotation() or iTween.ShakeRotation on the contained camera and apply controller scripts on the holding object.

    Hope that wasn't horrible written and impossible to understand... gotta get some sleep.
    Do everything as well as you can...
    http://itween.pixelplacement.com/


  5. Location
    Sydney, Australia
    Posts
    1,894
    And more than a year later, I've encountered the issue that I think you're referring to

    Not sure what you mean by "controller scripts on the holding object" though?

    I've been finding that when I use the shake, my camera slowly works its way out of position. As in, it doesn't return to the exact position it was in before the shake and gets further and further off center every time the shake is applied.

    I've been thinking about manually just recording the camera position, applying the shake, and then setting the camera back to the recorded position.


  6. Location
    California
    Posts
    1,657
    That's because you didn't do what pixelplacement1 said to do. iTween will make your camera drift away from its real position so that it won't return to exactly where it was when the shake started. You can fix this by creating a game object that you shake, and not the camera. You parent the camera to the game object either at the time you want the shake to happen or you do it at the beginning and put the game object at the origin.


  7. Location
    Sydney, Australia
    Posts
    1,894
    Quote Originally Posted by JustinLloyd View Post
    That's because you didn't do what pixelplacement1 said to do. iTween will make your camera drift away from its real position so that it won't return to exactly where it was when the shake started. You can fix this by creating a game object that you shake, and not the camera. You parent the camera to the game object either at the time you want the shake to happen or you do it at the beginning and put the game object at the origin.
    Yeah... that's why I was asking what he meant...

    In the explanation here, he's saying that you still apply the shake to the "contained camera" and apply "controller scripts" on the holder. I wasn't sure what those controller scripts might be.


  8. Location
    California
    Posts
    1,657
    Whatever camera controller scripts you are using to currently move your camera around would be attached instead to a container game object that is the parent of your camera. The camera shake script would be on your camera.


  9. Location
    Sydney, Australia
    Posts
    1,894
    That's exactly what I have set up, and the problem exists. I'm doing something wrong... I'll play around some more and see what I can figure out. Thanks!


  10. Location
    California
    Posts
    1,657
    If you have a game object that has the camera controller on it and the camera is a child of that object, you can reset the camera's local position back to origin once you have done with your shake. iTween offers callback functions that will invoke at the end of an animation, you can reset your origin in there.

Posting Permissions

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