Easily Control Cameras with Cinemachine in Unity!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
this video is sponsored by unity in this video we're going to look at sin machine and unity this is an excellent feature that lets you easily control your cameras with tons of options same machine is great for gameplay and also to handle cutscenes 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 enough tutorials made by a professional indie game developer so if you find the video helpful consider subscribing ok so sin machine is a camera system that gives anyone working with cameras the ability to create complex behaviors without having to write any code so if you're an artist designer or just someone who wants to make a short film inside of unity then sin machine is exactly what you need here we're going to look at how sin machine helps us very easily set a target for a camera to look and thought play around with valleys to make our camera work exactly as we want it set up multiple cameras and smoothly interpolate between them and in the end I will also showcase house in Maschine also works in TD now this video is an interesting one what I'm going to do here is essentially a smaller video version of a unity and learning premium of course so you feel like this and then want to learn more you can check out the entire course as well as many others by clicking the link in the description you need to learn premium is currently part of the mega bond sale going through March 31st so you can get one year of learn premium along with $1,000 worth of acids and tools for 90% off unity and learn premium is designed for those who want to accelerate their unity skills with advanced learning content there are over 350 hours of learning content on the platform including a 15 hour course on using AI in your games and a 22 hour course on mastering c-sharp so if you've been meaning to look at the entire learn premium then this is your chance for normal price you can get it through the bundle alongside tons of awesome assets and tools the link in the description is also an affiliate link so if you pick up anything through there you'll also be helping out the channel so check out the mega bundle sale get some awesome essence in tools and check out unity and learn premium thank you to unity and thank you too these are some supporters for making this video possible go to patreon.com/scishow to code monkey to get some perks and help keep the videos free for everyone ok so as I was saying sin machine is all about making complex camera movements simple sin machine does not replace your normal cameras but rather it works on top of them so you have a brain and a bunch of virtual cameras then those virtual cameras can be animated move around and do anything you want you can make them follow an object look at something cut or plane between different virtual cameras the brain processes on that data and creates the final shot here I will demonstrate sin machine mainly working in 3d but everything works exactly the same in 2d as well all right so let's start using it so over here I am in a basic scene over here I have my basic player character and I can move them around this nice small map and as you can see the camera right now is on a commune affixed position I cover this character controller in a previous video all I did was change the Y movement for a set movement and just like that now this character is moving in 3d so we have a nice demo scene now let's use sin machine first of all we need to add it to our project so open up the package manager then scroll down until you find the same machine and click on import just like that sin machine is now added onto the project you can confirm that it was in some correctly by checking all the way up here that there's a new sin machine many all right so with sin machine and sound let's start adding the main component which is the brain the brain is the component that acts as the main hub for all of the other sin machine components so it takes control of the camera and then allows you to work with various in machine virtual cameras so let's select our main camera and then we're going to add a component and then here we go into sin machine and add the same machine brain there's the brain component and as you can see there's tons of option to customize it the exactly how you want it but for now let's leave everything at the defaults and now that we have our brain we need a virtual camera the virtual camera is what actually defines the behavior of our camera so let's go up into our menu bar so click on sin machine and then in here create a virtual camera once you do you can see a new game object has been created in the hierarchy and if we inspect it we can see that it has a sin machine virtual camera component now over here as you can see we have tons of options now if you've ever manually worked with cameras then you know how it's quite a bit tricky to get them to simply follow and look at an object in here all we have to do is set these two fields so over here I have my character in my scene and I want this virtual camera to looking at it so to do that just drag the character controller onto the own look at field and just like that you can see that our virtual camera immediately snaps onto our target object and just like this if we try to play our scene and if there it is the camera is pointing towards my character and as I move around the camera correctly tracks my character all right so here you can see by just setting a simple field we have our camera correctly tracking a special object now over here the virtual camera has tons of options that you can play around it for example over here we can click on the aim tab in order to expand it and here we can play around with any of these values now the main thing is the ability to add a dead zone and a soft zone so down here we have the dead zone width and the South Zone width and height visually we can see some nice home from all gizmos so as I increase the dead zone width and increase the height and there you go you can see a little rectangle right in there so there's an air right down the middle then one outside of here and another one way out here so the middle one is the dead zone then this one out here is the soft zone and then out here it will never reach so once our character is inside of the dead zone then the camera will not move at all so as I move my camera in there as long as I stay in there the camera does not pan does not move it does not do anything then outside we have the subtle and as soon as my character moves into the South Zone there you go the camera now moves around in order to make sure that it's always looking at my character then here we also have horizontal and vertical damping so right now it's falling pretty fast as soon as my character moves and if I increase it by quite a bit then all of a sudden it won't track the character but it don't track it much slower then the red area is the end of the soft zone which again we can still modify in here and that means that as soon as the character goes outside our camera won't track it instantly regardless of the horizontal damping so as I move I move away and yep there you go as soon as I go into the red area it starts flowing instantly so you can see how just by dragging a target game object and setting a few options we already have some pretty complex behavior now for here the other film that we have is the phone field and with the formal film we also have the button here that we can set on for our options so for example let's drag our character controller onto the phone field and it instantly snaps right in front of the character then here we have the follow-up set so let's put it up and again the camera is always pointing towards the character so let's put it and push it a bit away just like that so with both of these now our camera won't look at the target and follow it so he's right in there and as I move to the left you can see the camera Pennington left Pennington right moving forward and moving backwards for some let's slow down the movement speed and let's increase the horizontal damping on our look and now if we move yep there you go you can see that he follows and he goes just like that so as I move away the camera is rotating towards it and then slowly moving in order to go onto this perfect follow offset position so again here we have some pretty complex behavior without having to write any code although obviously if you wanted to work with some code you could still do it for example you could easily swap out the target and look at with a different object so you know the game is running let's say now I want it to point at the cube and there you go now it's pointing at the Q and following the character so I move the character in the character moves but it's looking at the Q another option we have is having multiple virtual cameras so let's put this one so following the main camera and now let's make another virtual camera so we go into sin machine create a virtual camera okay so I had the new virtual camera this one is just looking at from a fixed point with a bit of a different field of view and if we play so first here we are with our camera correctly following and moving along with the player and now in the second camera if I increase the priority above the first camera as I increase there you go it smoothly interpolates between both virtual cameras so we're here I can move my character now let's lower the priority of this one and now it goes back onto the other original virtual camera so the same machine brain is smart enough to interpolate all of the values between them so whatever camera is active it takes on that field that position where it's looking in everything then you can also inspect the brain in order to modify how the default point works by default it's set to ease in and out and it's supposed to take two seconds but you can change it to anything you want for example it save 21 seconds so it's really fast and now let's lower priority this one angular straight down straight down just like that so you see how you have tons of options you can have as many virtual cameras as you want all of them looking wherever you want doing whatever you want it's an extremely customizable system then over here on the menu you can see that there are lots of different virtual camera types there aren't built to be very easy to use and fulfill a very specific need so if you got a free look if you want to move around to the camera you've got state-driven or to play around with various states you got a clear shot to make sure that your target is always in view and so on then down here like I said scene machine also works in 2d so let's check this out so here I am in a 2d scene with my normal player character just moving around all I have is a basic static main camera and now here I just go into the menu send machine create a 2d camera as soon as you do it creates a virtual camera and adds the send machine brain onto the main camera so now let's position the virtual camera accordingly and give it a target so drag the camera onto the follow act and again over here play around the damping and so on and here we also have a bunch more to these specific features all right everything's set up and just run and okay here's my character and as I move it there you go now the camera is correctly tracking my character so you can see a nice virtual camera working perfectly in 2d and again here I can play around priority so here I have one specific camera very zoomed in then lower the priority and immediately smooth on to the other large cameras there we go just like this I'll go in zoom in and go out and zoom out all right so you can see how the power of sin machine works both in 3d and 2d all right so here we looked at scene machine in unity again this video is just the getting started based on the same machine course on unity learned premium the course has a lot more content diving deeper into this machine brain covering how to make a dolly track interacting with timeline to make some cool cutscenes and lots much more so if you want to learn more about sin machine or check out any of the over 500 tutorials available on the platform then click the link in the description right now there's the grow your skills mega bundle sale happening on the assets or it has a total value of over a thousand dollars for ninety percent off including one year of unity learned premium the link in the description is also an affiliate link so if you pick up anything through there you'll also be helping out the channel thank you to unity and thank you to these are some supporters for making this video possible go to patreon.com/scishow to code monkey to get some perks and help keep the videos free for everyone subscribe the channel for more Hinton journals post any question haven't comes and I'll see you next time [Music]
Info
Channel: Code Monkey
Views: 51,510
Rating: undefined out of 5
Keywords: unity cinemachine, unity cinematic tutorial, unity camera, unity cinemachine 2d, unity cinematic, unity camera follow player, unity cutscene, unity cutscene tutorial, code monkey, brackeys, 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, camera
Id: Ml8ptNeezsU
Channel Id: undefined
Length: 12min 20sec (740 seconds)
Published: Sun Mar 22 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.