Master Cinemachine in Unity3D

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] all right welcome to this tutorial on cinemachine in unity now cinemachine is a very very powerful tool it allows you as a game developer to take your game from being just a game to being like a hollywood blockbuster style game where it allows you to create cut scenes and panning around and and adding like visual cues that would just make your game look like a like a hollywood hollywood project it's just incredible what what cinemachine can do and how powerful it is so our goal today is to uh learn how to use how to bring cinemachine into our project and then also to create a camera that would a camera that will follow our character all right follow our character around we're not going into character movement that that was a past tutorial so you can lean back to that and then we're going to create a uh a panning camera to pan around our our little terrain area here so i created i went ahead and created a basic terrain a simple terrain here and i grabbed unity chan off of the asset store so unity chan is free to download and i brought into my project so my project ready to go so if you want to pause this video and go ahead and create something for yourself you can go ahead and do that as you follow along in this video but i'll forge ahead and the next step would be to jump into package manager and we're looking for is cinemachine and cinemachine would actually be under not under my assets but under the unity registry so we'll search again there it is set a machine i've got i've got it right there let's hit install let it do its thing all right so at this point uh you should it might take a bit of time for cinemachine to install onto your project uh so i went ahead and sort of fast forwarded here onto it being fully installed there were some console errors that popped up so i went to my console and just hit clear and it looks like they're not recurring so it looks like i'm okay now the first thing you'll notice is that a new drop down appears called cinemachine and what you see here is uh now you have a list of different options for cinemachine and the basic one that we're going to start with today is the virtual camera so every camera you're dealing with is a virtual camera so what we're going to do is first off i'm just going to add a virtual camera to my project and i'm going to call it i'm going to rename it to i'm going to call it third person cam all right and from there i now have a third person camera and if i look at the options here under third person camera the the two main ones that pop up into my head are follow and look at so this camera its purpose is that it's going to be following the our our character in this case unity chance so if i switch back to the scene here we want to have this camera follow unity chan so all you have to do is you take your character in this case yuri chan from the hierarchy and you drag her over to both follow and look at all right now you can adjust yuri chan uh sorry the the view of yuri chan as you see fit like right now looking at yuri chan in the game view we're not really seeing too much here that that that a typical player might like unless you know that particular that happens to be the particular uh look that that you're going for in game maybe maybe that's what you want but realistically most likely not so you won't use so you won't use these arrows to move your camera around instead you're going to look to your tracked offset object here and what you're going to do is you're going to adjust the x and y see there's the x there and i'll just ctrl z to undo that and look at y so y is pointing it up and down so there's your rotational y i'm going to come back to that in a sec z i pronounce it said i'm going to have to raise it higher and there's also the offset too so the aim is is one thing where you can look at but if you really want to if you need to move it around like like my zed is taking pharah to move i'll look at the z up here so there we go we can zoom in like that or with y that's better now we're up in the air a bit which is what i wanted and i'm okay with the x as it is so i'll undo that z i think that's how far i think that's a good view for what i want and i can go back to tracked offset object or object offset and i can try rotating the y a bit more but this will just take some fine tuning from your perspective and how you feel you want to go with this so now i'm just going to ctrl s to save my scene so i don't lose anything if i run this and there we go so we have a proper view of unity chan in the game you shouldn't be seeing the box or the border around here this these buttons came with yuri chan this prefab in particular i don't i'm okay with it but i wanted to point you to something here that didn't pop up right away and there's this little icon here next to main camera this is the this is the cinemachine logo it didn't pop up right away probably because my computer was a bit delayed because i got a number of things going on here on the computer but what you should be seeing this logo next to main camera to tell you that cinemachine is attached to your main camera and so now anything you do has to go through cinema machine so this is a good thing seeing this this little logo here now if you were to go ahead and add and add a character controller and add a script to do your character movements your character moving around your character then you would see this camera follow every follow uh yuri chan all over this little terrain here but that's not the goal of this lesson so the goal for this lesson was to get you easily up and running and connected with with cinemachine to be able to have your virtual camera follow all right so now that was pretty easy let's let's start getting into cut scenes so we're going to add another virtual camera so what i'll do is i'll go set a machine create virtual camera i'm going to name this one uh cutscene cam all right now here's the thing the my end game here for this little exercise is that i want to do i want to run my cut scene pan around the world here and then switch over to the third person cam right kind of like how you might see a typical game where you're moving around the the world you're seeing all these amazing little cut scenes and all of a sudden zoom you're into your game and you're into being third person to your character right so i wanted to pull off something like that here today so what i've done is i've got my my cutscene cam and i got my third person cam we actually need one more thing out of cinemachine and this is called a state driven camera so i'm going to say create state driven camera and i'll leave it as default name i can't really think of a name for it right now but what i'm going to do is i'm going to drag cutscene cam to it i'm going to drag third person cam to it but i don't want i don't really care about this cm vcam thing right now so i'm going to delete this because i'm going to just have my two my two cameras here all right and so now that i have two cameras cutscene cam and third person cam uh right now in game you're seeing you're seeing the the cutscene cam as having higher priority the the thing is is that with uh with with these virtual cameras there's a priority option right here under each of them sorry under each of them right there all right even the state driven camera has the priority level as well so when you want to toggle between cameras you set the priority level so i'm going to give cutscene cam a bit of a higher priority so i'll give it an 11 because i want cutscene cam to be the first camera that runs all right so now we're going to do is we're going to animate our camera around this world so we want to keep the focus on yuri chan you want to keep our cutscene cam looking at unity chan the entire time or at least facing in her direction and and just pan around the game world for that awesome look and feel to our game so first thing we need to do is we're going to look at the follow and look at for for the cutscene cam now i said that we did this we did this for the third person cam already but we're not going to follow uh we're not going to follow unity chan we'll just keep looking at unity chance so i'm going to drag unity chan's prefab into the look at portion so i want to keep it continuously looking at her this gives us a warning with body saying that body the transposer requires a follow target i'm going to change it to do nothing i don't really want the body to constantly be following now what i want to do is i want to animate the i want to animate this this the camera around the game world so what i'm going to do is i'm going to take full advantage of the animation tab and you probably have seen a create button you'll want to hit create create a file i already have something open already so i'm just going to continue on with this but you should hit create and save a file somewhere for your animation now so all we have to do is if you recall from animations in in a previous lesson uh we we just hit the record button and we start so we've hit record and now i'm just going to move my timeline marker to somewhere further in the future because right now i want to start at this location so what i'm going to do is i'm going to actually you know what i'm going to start somewhere closer so i'm going to hit the zero zero mark and i want to bring my camera to be sort of facing uni chan just up and close so what i'm going to do is i'm going to add a property here so under i'll just do it again so it's going to hit add property transform position i mean it'll actually automatically add these properties as we go but actually what i want to do is i want to delete this and i want to delete this that it auto generate i want to create my own i guess it just deleted anyway but what i want to do is i want to bring the camera like i said closer up to yuri chan so i'm going to start playing with this it'll take some playing around with to get this right but i want to have it like right up close and personal to her so there we go i want to start at this side bring the y closer bring the z that's it getting there so it takes a bit of fidgeting to get it just right almost there almost okay perfect i want to start this this is going to be my first location in the timeline now let's say uh 15 seconds over maybe 10 seconds over don't want to go don't take too long now what i want to do is i want to rotate out so now i'm going to rotate away to here all right maybe at the 20 second mark we'll keep rotating let's zoom out a bit and there we go a rear shot we'll zoom pan away from the world and we'll go up all right maybe at the 25 mark we'll pan over to the other side of the world like that and of course play around with it and see what see what your see what you like like this is the perfect time to ex to play with and and explore okay it's about there and then finally at let's say the 30 second mark we're going to zoom right in behind unity chan pan around there and there we go and that's perfect so now we'll hit we'll hit stop record and let's see this thing in action hit the play button way too fast way too fast so we'll probably want to actually slow this down so all is not lost we'll just drag our markers out further let's try again still fast there we go there's there's that's what i was looking for so there's the i was using the scroll wheel to move things out to zoom out just i think now we're in the seconds mark that's better okay let's get this really zoomed out to around the 35 second mark let's say this will be about the 28 second mark about the 20 second mark about the 13 second mark and let's try again that's better a bit slow but of course you can play around with it get it to be to your liking so the cut scene thing you know it took a bit of time here to really get it to where we wanted it to go but here we go now we have this amazing pan around it's exactly what we're looking for now i have to warn you you notice that i made the state driven camera first then i dragged my cutscene cams in and then i made this animation so be very careful that you do it in this order you make your animation after you've dragged your cutscene cam in as a sub object to your to your state driven camera because you may lose the animation that you've created right and so all that work goes down the tubes but here we go we have a nice little panning camera all right now the trick is to get it to switch from this to our follow camera all right so this is where the animator will come into play so i'm just going to hit so i'm just going to click on my animation tab ctrl s to save to verify that hey it did save and sort of flush all these changes to that to that animation file cutscene can anim all right so so it's there so we have it saved we have our beautiful cut scene cam here if i hit play let's see what happens so there we go it's actually running it so there we go there's our and of course this is just educational purposes of course you could probably come up with something ten or a thousand times better than what i did i have full faith in you guys out there to do something way better but but you get but the idea here is to understand that hey we're able to create this amazing animated virtual cam like a nice little cutscene cam and it's not very difficult to do and so now at the end of this animation we're sort of zooming towards unity chan and now at this point we need to we need to be able to switch over to our follow cam all right so we're going to need is we're going to need to do an animator so we'll do is we'll switch over to our state driven camera there's a bunch of settings here we haven't touched yet with this with this and now we're going to focus our energy here but first we need to do is we're going to say add component we're going to look for an anim we're going to add animator so we have animation we need we create an animation we need an animator and just to recap an animator is essentially a sort of state machine that allows you to switch from state to state so we've created our animator now we need an animator controller so we got to create one so what i'll do is i'm going to switch over to my project and i already have a folder called camera and it's basically all the animations related to the camera let's get the plus sign and i'm going to say i look for animator animator controller that is and call it uh let's see state driven animator or whatever name you feel like calling it all right now i'm going to drag and connect this state driven animator to my state driven cameras controller argument there all right now that this is connected i'm going to switch over to animator right and making sure that this thing is highlighted let's bring everything zoom in so it's easier for you guys to see all right so this is our state driven animator controller making sure this thing is highlighted we're going to add some states so right click and say create state and another this is our first state so our entry is going to go to this new state and create another new state all right let's rename these states so first off entry to new state i'm going to change it to cut scene cam i'm going to rename this second one to follow cam and i create a transition from cutscene cam to follow cam now if you don't understand what i'm doing here with first of all with the animation and with the animator then you want to switch over to my lesson on animations and i walk you through these two tabs and we use this to animate and and really enhance the look and feel of our uis and in-game uh characteristics for an earlier lesson so i already go through this in the past so you'll want to jump to that lesson for a better understanding all right so we have here our states the trick now is to associate them uh with the animations in in question so we're going to switch back to our state driven camera now first actually before we do that let's just do a control so clicking on the animator tab do a control s to save just to verify that our our steps that we did here were were saved so i'll even click somewhere in here just so we don't lose this by accident now switch back to state driven camera one you'll notice that there's animated target as well and so you want to do is you want to set this to your state driven camera so we'll say cn stay cm state driven camera 1 animator actually instead of that we'll uh actually drag the state driven animator here right so yeah basically yeah we got the cm state driven camera one animated target that's this thing and it's going to use this animator for it now what we need to do is we need to add in our we need to set up some custom blends so it's going to blend from camera to camera so we'll hit create asset next to custom blends and i'm going to move this also to our camera and just give the name cm stage everyone blends all right and we need to add some states all right we need to for both this state and this state so uh we'll start with the custom blends we'll hit plus we'll say from any camera to cut scene cam we'll do an ease and ease out all right and then we'll add another blend going from third from sorry from cutscene cam to third-person camp now what this does is it tells the state machine that when we want to switch from these from this transition to this transition to perform an ease in ease out and you can play with it there's cut there's ease in ease out hard in hard out linear custom so after we're done this play with these styles to see how it does these things you'll see that i want to have a smooth transition from one camera to the other so i'm using ease and ease out here and let's do it like a little control s to save right now below it there's states and we need to map our cameras our virtual cams to these states here so i'm going to hit plus and say new state and i'll start with cutscene cam i want to map it to the cutscene cam camera now notice i kept the the names consistent in this case i'm gonna do another new state and this will be follow cam will be mapped to third person camp all right so what we're seeing here is that this cutscene cam state will be mapped to this cutscene camp and this follow cam state we map to third person cam now let's see what happens we're not done yet but let's see what happens when we run this it starts there and actually just jumped right to third person cam you probably saw up here it went from this state to this state right away so it kind of tried to do the cutscene cam but it didn't get very far and it jumped right to follow cam so we got to do something about that so we need to do is we need to look back at our our animator state machine here we're going to click on the transition here and we have a has exit time it's already checked off if i expand settings its exit time is actually uh three quarters of a second our animation is is something like i have to double check the timing here to get it right it's uh 30 i'm going to say 35 seconds all right so we need to do is and just double check it's not shorter than that so we don't lose anything there so i'm going to set the exit time to 35 seconds i'm going to switch back to animator and there we go so click on the transition so make sure you are in cm so you can really get lost on this be very careful where you're at making sure that cm state driven camera is highlighted when you switch over your animator tab click on the transition between cutscene cam and follow cam and change that exit time to 35 and let's see what happens now so we're starting there we're panning panning panning you notice that my animator is still sitting at cutscene cam zooms away so we got to that portion and you notice that this is all about timing it's all about timing right but unity and cinemachine and the animator animation tab that is make life so much easier for you here we go panning in and there we are and we switch from state to state we've switched right to our our rear view of unity chan right to follow you so now at this point what you'd want to do is you'd want to add your character controller get your get your character controls up and running for up down left and right on the keyboard or if you're using mobile controls at your mobile controls you can move unity chan around this game world but there you have it so this was an introduction to cinemachine and we've learned how to be able to add a follow camera to fault to be like the the third person view of our character and also to create a cut scene right and we use the state driven camera to be able to switch between the two cut scenes so there you have it you now at this point take this project grow it and see what you can do with it and see what the amazing cutscenes you can create are all right until next time i'll see in the next tutorial take care and bye for now [Music]
Info
Channel: Jawaad Sheikh
Views: 221
Rating: undefined out of 5
Keywords: unity3d, learn to code, tutorial, animation, animator, virtual camera, state driven camera, cut scene, cinematics, third person camera
Id: 4esx0uC-kI0
Channel Id: undefined
Length: 27min 35sec (1655 seconds)
Published: Wed Sep 22 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.