How to do Camera Shake with Cinemachine!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video we're going to apply some camera shake using cinema sheen this is a very simple effect that you can add to your game to make it feel a lot but adding it to your scene machine virtual cameras is very easy let's begin [Music] hello and welcome I'm your code monkey and this channel is all about helping you learn how to make your own games with nf2 torrents made by a professional indie game developer so if you find the video helpful consider subscribing ok so let's add some nice and simple camera shake now normally I have all my cameras with a custom script but I've been using same machine more and more since it's so useful but when I went looking into how to apply camera shake to same machine I couldn't find much information on it so if you're facing this issue then hopefully this video will help since it really is very simple okay so here's my scene I have my simple player character I can move around and shoot and right now there's no camera shake so it makes the shooting feel very weak check out the code monkey app on Steam interactive tutorials complete games and more click knowing the description and add it to your wish list this video is made possible thanks to these awesome supporters go to patreon.com/scishow monkey to get some perks and help keep the videos free for everyone alright so let's add it now here in the editor everything is set up using same machine now if you're not familiar woodson machine then check the link in the description where I cover the video on how to get started here the main camera has the same machine brain and down here is the virtual camera so it is simply set up just to form with this player character it's a very basic setup and now the key for adding screen shake is very simple down here we have a film for the noise so change it from none to a basic multi-channel permanent and now we can see that we need a noise profile now there are already some pre-made presets so for example let's use e60 shake and now here we can play around with these values so here with the game running we can see the noise in action now here by modifying the frequency we can adjust how often the camera shakes and by modifying the amplitude we can adjust how much it actually shakes so as we increase then each shake moves the camera much further so in this case what we're going to do is set the frequency to a certain value and then all we need is a script that sets the amplitude to a certain amount and then slowly decreases it back down to zero all right so let's make that script here now let's create a new C sharp script compass our scene machine shake and let's write the script on to our virtual camera game object okay now in here first we need to grab our virtual camera so let's get it on our awake up here we need to add using same machine then we can do a get component of our scene machine virtual camera alright we have a film for our camera now let's make a function to shake it here we're going to receive a float for the intensity of the shape and also a float for the timer so we're going to shake the camera using this intensity for this long and now we access our scene machine virtual camera in order to set the amplitude so we go into our scene machine virtual camera we get this in machine component of type of our basic multi-channel per line and then we modify the amplitude game and we set it to that intensity alright so this won't make the camera shake and now here we have two methods that we can use for handling the time one approach is to only the amplitude at this amount and after this amount of time we drop it to zero or we can slowly decreases over time let's first try out with the simple timer so let's store it in the field and here we set it okay then we have our private rolling update where we're going to count down the shake timer alright so if we have a shake timer then we count it down by time.deltatime and then if it's under zero then once again we grab our multi-channel purlins and we set the amplitude back to zero okay so now all we need to do is to call this script from somewhere now in here I have my player script and here is where I'm handling the shooting so it's just doing a bond with recast and spawning some effects so it's in here that we want to shake our camera now back in our sin machine shake we want this to be very easy to use so in order to do that let's make a static instance so we have our static instance that we set on our wink so now back in the player here we can access our same machine shake access the instance and call our shake camera function now let's give it some intensity and some time all right that you do it let's test ok so here I am and shoot any of their yo it did indeed shake now when I should it's shaking way too much but yep there your we have our camera shake using sin machine so here it is with a more manageable intensity right awesome so this is our first method it simply starts and stops shaking after one now let's movement the second slow drop method so here on our update instead of counting down the timer and then setting it to zero what we need to use is our math work so this interpolates a value between a and b over t so we need our starting intensity so we have the starting intensity and we're going to want to order that starting from the starting intensity going towards zero and over time which won't be our time so we store the shake timer total and as the shake timer goes down then this one essentially start from 1 and go down to 0 right so we just apply this alert ok so just like this let's test ok here we are and shoot and you clear yo now it's a bit more so so this one goes down a bit more smoothly than the other approach now which one you use brown depends on what design you're going for when I snap your n1 is smoother this method for example would be better if you had some sort of explosion so as I shoot if there are your shakes a lot and then slow only goes back down to zero so again relative the usage alright so here there is a very simple effect which now you know how to apply when using sin machine check out the code monkey upon steam interactive tutorials complete games and more click knowing the description and add it to your wish list this video is made possible thanks to these awesome supporters go to patreon.com/scishow to code monkey to get some perks and help keep the videos free for everyone as always you can download the project files in Ataris from mt karma calm subscribe to the channel for more unity tutorials post a new questionnaire when it comes and I'll see you next time [Music]
Info
Channel: Code Monkey
Views: 80,901
Rating: undefined out of 5
Keywords: unity cinemachine screen shake, unity camera shake cinemachine, camera shake, unity screen shake effect, cinemachine shake, cinemachine, unity cinemachine, unity screen shake, code monkey, unity tutorial, unity game tutorial, unity tutorial for beginners, unity 2d tutorial, unity 3d, unity, game design, game development, game dev, game development unity, unity 2d, unity 3d tutorial, programming, coding, c#, code, software development, learn to code, learn programming
Id: ACf1I27I6Tk
Channel Id: undefined
Length: 7min 34sec (454 seconds)
Published: Wed Jun 10 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.