CAMERA SHAKE in Unity
Video Statistics and Information
Channel: Brackeys
Views: 396,543
Rating: undefined out of 5
Keywords: brackeys, unity, unity3d, beginner, easy, how, to, howto, learn, course, series, tutorial, tutorials, fix, tip, game, development, develop, games, programming, coding, basic, basics, C#, shake, camera, camera shake, position, movement, earthquake, explosion, explosions, turbulence, chaos, EZ, EZ Camera Shake, Shaker
Id: 9A9yj8KnM8c
Channel Id: undefined
Length: 9min 28sec (568 seconds)
Published: Sun Feb 25 2018
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.
Wouldn't it be a problem if multiple sources called the camera shake? Then it would set the original position to what it was when the camera shake was called, and possibly reset the position to some weird position due to another camera shake taking place.
Just use Cinemachine, it already has shaking in there.
Hey brackeys!
An artist asked me to add camera shake recently, so I've just done this. I'm not a huge fan of this solution. If several things call the camera shake at once, it will mess up the original position, something that will also happen if the main camera is disabled and reenabled for any reason during the shake (because that kills the coroutine and the camera will be in the "shaken" position), and it's very hard for a designer or artist to invoke camera shake like this. Also, as he mentioned, there's no way to do fades or things like that.
The solution I went with, which solves virtually all those problems, is to do something like this:
Essentially, the camera is "always" shaking, but with magnitude set to 0.0, it's just standing still. This basically solves all of the problems: one shake at a time, no losing track of the camera's origin (even if it's disabled or even assemblies reloaded), and it has a HUGE bonus: since the magnitude is just an exposed field like anything else, it can be animated. An artist or designer can tightly control how much the camera is shaking, how it fades up, down, everything, using either regular Animators or the new Timeline.
It's a good tip if you're aspiring to be a Unity developer: at some point, you're going to work with (and for) people who aren't programmers. If you're making a feature, think about how you can get them to use it, through things like UnityEvents, Animators, Timelines, whatever. Also, don't use coroutines if you can help it :)
My solution was slightly different than this to suit our game, but this was more or less the gist. Worked really well.
Just watched this last night.
Oh nice! Haven't watched this yet, but if I crash horizontally into a wall in a 2D racer, can I set the vector to the direction of the impact? That's something most camera shake tutorials miss. They just apply a generic noise which is not great.