2D Camera in Unity (Cinemachine Tutorial)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
something you always need when making a 2-d game is of course a good camera and trust me if there's anything that's cost me a lot of pain and weird spaghetti code it's cameras luckily unity has made the process so much easier by adding a really solid set of features called cinema sheen and one of the coolest things about cinema sheen is that unlike this guy the cameras never run out of battery so in this video we'll turn this boring scene into this but first this video is sponsored by a skill share skill share is an online learning community with more than 23,000 quality classes on game development tech and more without channel kind of having a 2d theme at the moment I thought I'd mentioned they are complete 2-d game guide this guide is made by Christopher Navarre and gives you a complete crash course on how to develop 2d games in unity plus it also teaches you how to manage prefabs you see sharp scripting and much more a premium Skillshare membership gives you unlimited access to all classes for less than $10 a month so to get started simply click the link in description and the first 500 people will receive the first two months for free alright let's jump into the video so cinema Sheen is actually one of those parts of unity that isn't included by default luckily we can really easily get it by going to window and opening up the package manager let's then take this package manager and dock it at the bottom and you can see all the different packages that are currently included in our project we can also go to all in order to get a list of all the packages that are available to us let's find cinema Sheen and let's go to the right here and hit install and that is all we need to do we now see that in our project we have cinema sheen and it says that it's up to date so now to start using cinema Sheen we'll go to the top here where it says cinema sheen and here we have a bunch of options for different cameras that we can create of course the camera that we want to make is a 2d camera so we'll go to the bottom and hit create 2d camera and right away this might look really weird but fear not what's happening here is actually fairly simple so basically what we just created is what we refer to as a virtual camera you can see over here it says cinema Sheen virtual camera and the virtual camera is basically just like an empty object it's not visible in our scene and the only thing that it has is basically a in a rotation as well as some camera settings however what's in a machine that does is that it applies all the settings of our virtual camera to our actual main camera so if we go into the scene here and shift out of 2d mode we can see that we now have our virtual camera right in the center of our world here and that our main camera is at the exact same position in fact if we go ahead and move our virtual camera out so we move it backwards here we can see that the main camera follows and if we go into our virtual camera and adjust the orthographic size remember we can always use this in order to zoom in and out on a level let's set it to something like 5 this also being applied to a main camera you can see that that now has a size of 5 and at this point you might ask well if the only thing this object is doing is just adjusting our main camera well then why do we need it at all why don't we just adjust all this stuff on our main camera and be done with it and we could definitely do that for this super simple setup however using virtual cameras makes it really really easy to blend from one camera to another because we can have multiple virtual cameras in our scene and then just have our main camera switch between them so I'm just going to go down here and close our packages we don't need them anymore and now under this virtual camera we can see that we have a bunch of different settings and a lot of these we're just going to leave as is however one really important thing is that we can input an object here that we want to follow around of course the object that we would like to follow is our player so I'm simply going to take our player object and drag it into the follow slot and right away we can see that our camera snaps to our player in fact if I was just to go ahead and hit play now we actually already have a fully working 2d camera so you can see just how easy it is to set up cinema scene and start working with it of course cinema Sheen is a really powerful tool and there's lots of settings field that we can configure in order to change the way that our camera behaves if we go into where it says Barney we can change how our camera follows or player around so let's start by just setting all of our damping to 0 let's also set our debt zone width and height to 0 as well and what we have here is probably the simplest way to track around a player the camera will always stay right on top of the player and we apply no kind smoothing to the camera to make it look better now let's make this a bit more sophisticated let's first of all adjust where we want our character to be framed on the screen right now he's dead center whenever I'm doing platformers I usually like to put him a bit above the middle so I'm gonna go ahead and adjust a screen why in order to pull him up a bit I just think that looks a lot better we can also add what we referred to as a dead zone let's try and increase the dead zone width and height the dead zone is basically a place on the screen that our character can move freely without the camera following him you can see if I move to the sides here the camera stays in place because I'm moving within the dead zone however at the moment that I step outside this zone we can see that the camera moves and this is true both for x and y now I think this dead zone here is probably a bit overdone but I definitely like to have a tiny bit in there so I'm gonna set my dead zone with to something like point two and the height to point one I think it's nice to keep the dead zone height fairly minimal so that it doesn't mess with jumping too much we can of course also smooth our cameras movement to do this we'll go and adjust the X&Y damping let's try setting both of these to one and we now see right away that our tracking point this yellow point right here actually gets to exit the dead zone because the camera is kind of smoothly following it whereas if we completely remove damping it will never leave the dead zone now I definitely recommend playing around with damping to find the right settings I'm gonna try setting these to three and you can see just how much smoothing this applies and in turn you can also put it at a fairly low number if you want really snappy controls I think in this case setting it to one works pretty well another setting that is often used for platformers is look ahead now this setting is meant to get rid of a very simple issue if we have smoothing on our camera as well as a dead zone and we start to run in a particular direction we can see that it's pretty hard to see what's going on in front of our character until there's something right there in other words it would be really nice if we could look kind of in front of the character and the camera recognized that we wanted to do this to do that we use these luga head settings if we increase the look ahead time to say something like 0.5 we can see that as soon as we start to move in a particular direction the tracking point moves forward in order to allow us to see what's in front of us now this might be a bit overdone but it definitely makes it much easier to see what's happening the look ahead time at just how much we want to look ahead so if we set this to one we can see that we're looking really far I'm just gonna set that to something like point three and as the name suggests look ahead smoothing allows us to smooth out this aberration so we can set that to twenty in order to get it really slow and smooth pan forward I'm going to set it to five in order to make this change really quick I'm just gonna leave it at something like ten finally one thing that I really like to do is ignore the why whenever we're looking ahead and that's because I really don't like what happens to the camera when jumping so I'm just gonna go ahead and press that and now we can see that when jumping nothing happens but it still happens on the X and that's pretty much the settings that I normally use finally we also have some settings down here that I rarely adjust these allow us to change this so-called soft zone if we go ahead and decrease these we can see that the red lines get smaller on the screen and you can see that as soon as the tracking point tries to exit the soft zone it just completely snaps and this ignores any kind of smoothing so this is nice to have in the case that your character moves extremely fast and you want to quickly follow him in this case you can just leave the soft zone at point eight point eight this way the character will always stay on the screen or if you don't care about this effect you can always press unlimited soft zone and that gets rid of the red lines altogether however I like it so I'm gonna put it back oops I accidentally removed the dead sounds let's just put that back that's pretty much it if you want to remove the window guides you know ways press this button here or in simply deselect the camera and now if we fullscreen and play the game we have a nice working camera that will follow around our player pretty cool that's pretty much it for this video if you enjoyed it make sure to subscribe and bring that notification bell so you don't miss the next one also we've started an Instagram for all kinds of behind-the-scenes stuff it's really fun and I definitely recommend you follow us at practice team on that thanks for watching and I will see you in next video is it working thanks out the awesome patreon supporters who donated August and a special thanks to Alexander player Simha yo cheetah 3d infinity PPR to VR systems Sybok mummy Dirk Eames Kirk personify thanks to long-lived assets Clinton vents qeh Ronan Dan Sullivan for breezy Tim afford a park James P Bruins cat now Kiyosaki Gregory Pierce Larry tweet curse whiskey James Rogers propfan Robert Bundy Anthony patent and Erasmus you guys Rock
Info
Channel: Brackeys
Views: 533,324
Rating: 4.9525084 out of 5
Keywords: brackeys, unity, unity3d, asset, assets, beginner, easy, how, to, howto, learn, course, series, tutorial, tutorials, tip, game, development, develop, games, programming, coding, basic, basics, C#, 2D, 2D camera, camera, 2D tutorial, cinemachine, follow, smooth, lerp
Id: 2jTY11Am0Ig
Channel Id: undefined
Length: 9min 18sec (558 seconds)
Published: Sun Sep 09 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.