Using Timeline for Cutscenes in Unity: How to make a game like Zelda using Unity and C#

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

Thank you for making these! I hope you keep going as long as you can :)

πŸ‘οΈŽ︎ 3 πŸ‘€οΈŽ︎ u/P0ck3t πŸ“…οΈŽ︎ Mar 28 2019 πŸ—«︎ replies

I've been working on a similar project in my free time lately (have a broken knee, and am in abundance of free time), and your videos have helped me solve a lot of issues i was having, so thanks!

πŸ‘οΈŽ︎ 2 πŸ‘€οΈŽ︎ u/Mr_Dionysus πŸ“…οΈŽ︎ Mar 30 2019 πŸ—«︎ replies
Captions
all right welcome back so today we're gonna be making cutscenes this is something that's been asked for for quite some time so you might notice that my video numbering is different this is supposed to be video number 59 in this series but since I feel like people could do this cutscene stuff without meaning to follow the other 58 parts I mean if you're just coming here for cutscenes this is gonna help you so let's take a look I've got this project and you can find it on github or you can be using your own project but I'm just gonna hit play and let's see our little cutscene play out so we're gonna have our scene fade in and walk forward we're gonna walk right we're gonna ask ourselves a little question and then now we can control our character and begin the adventure so thanks for joining me and let's dive right in [Music] okay so what we're going to be doing today is I'm gonna be first I want to clean up my prefabs a little bit so my player prefab if you open this up you can kind of see there's some things that I've added that aren't part of the actual prefab you can see the things that are grayed out that are part of the prefab and the things that aren't grayed out currently aren't so if I click on the player I want to go to my overrides maybe it's not overrides it's open the prefab yep no those are both there so I guess that's fine but I want this prefab to be the one that's in my actual prefabs folder and I think right now it's not if I open the one that's my prefabs folder yeah this one doesn't know what all that other stuff is so I might be breaking stuff here but I'm gonna delete that player prefab yep and the actual player prefab is this one because this knows yep it knows all that stuff alright cool so I'm gonna go back and I know where my player is now I want my I want to have an opening cutscene to my game so when the player goes to choose a new game I want to have a little cutscene in the house where the player starts up by the bed moves to a certain place a little dialog box pops up and then they the and then the player can control the game so let's let's do that so I'm gonna go to my scenes folder here I'm gonna grab my house interior I'm gonna duplicate it by hitting ctrl D I'm gonna change this from house interior to opening cutscene and then I'm gonna open this up and I want to this is missing its prefab so let's delete that yep told you I to break stuff by doing that go to my player and I'm gonna drag this prefab into the scene no this has some objects on it that are from a patreon tutorial this lighting effects so I'm just gonna turn that off no big deal I want my player to be let's put him at zero negative two point five so nice even position like that alright and just make sure that these are set up cool so what we're gonna be doing today is we're gonna be using a unity system called time line in order to make our cutscene we could use the Unity animator however timeline is a way of taking the Unity animator and making it a little more organized when you're gonna have to manipulate multiple objects at once like we are so I'm gonna add a new object to the scene create empty and I'm gonna call this my timeline manager and I'm gonna add a component to this and the component I'm gonna add is called a playable director now my update method I want to be game time my wrap mode I'm gonna be have I'm gonna have that at none and I want it to play on awake now you can change that play on a week like for example if you wanted a cutscene to happen when your player entered an area you could have a trigger and then when your player enters the trigger you could tell the playable director to play the timeline cutscene that it has now the other thing I have to make is a timeline asset and this is actually the third time I've recorded this video so I already made a folder in my assets folder for timeline and I'm gonna delete this just to show you how to create a timeline asset delete alright so I made a folder for timeline and go ahead and right-click and we're gonna create and we want to make a timeline and I'm gonna call this opening cutscene now I'm gonna go back to my timeline manager and my playable needs to be the opening cutscene I'm also gonna go to window and sequencing and choose timeline and that opens up a timeline window you know change to my scene view so I can see everything and dock my timeline window down there now I want to keep things nice and neat so I'm gonna add a track group specifically for my player so this is going to be the player track and I'm gonna add another track group for the dialogue box tract group this is gonna be dialog box timeline can give you can get really messy if you're not keeping things kind of organized like this so with the player selected I'm going to add an animation track and this needs to know what animator we're pulling from and we're gonna pull from the player so I'm gonna pull that in player animator and now I need to know what animations it should play so this is why we've had all of our animations kind of nice and neatly sorted into folders here I'm going to go to my player animations I want my player to start up here walk down walk right look back down say something and then that way our player can can take control so first I want to have the idle down so I'm gonna grab idle down and pull that in here now idle down is a really really short animation it's just one frame so I'm gonna make it oops I have to zoom in here using the scroll wheel come on now there we go and I want this to be all the way over at zero my mouse is fighting me now as I pull it up over you can see that we hit these l1 l2 l3 that's kind of how many times it's repeating so right now we're getting it to repeat 10 times let's go for 30 so 30 frames which is about half a second roughly then I'm gonna have the player walk down I move that over and we'll have them walk down for let's say a full second so I'm gonna pull this over no it's fine like that well no I'm gonna pull it over to say 90 then I want them to walk right so I'll drop this in and I'll pull that over to save them 50 and then I want them to face down so idle down they're gonna say something so we need to zoom in here pull this over make it wider you go to say there all right so we're idling down we're walking down we're walking right and then we riding down so when I hit play here I should see the animations just go through I'm not moving the player yet I'll cover that in just a second but I am I should be going through those animations so let's try it out okay cool so there we go we've got the animations working now I want to actually move the player from space to space to space so I'm gonna add a new track and this is going to be a knots on a control track it's another animator track I think yep and I'm gonna use the player again because that's what I want to animate and for my player here I want to start with my player I want to start with my player up in me say up here right next to the bed now I'm into record when I did that so timeline manager record so I want my player up by the bed then they're gonna stay up by the bed until idle down is complete so I just want you to stay there and then walk down as complete our player is gonna be come on move over there we go when walk down is complete our player is gonna be down here and then when walk right is complete our player is gonna be over here and I'm gonna I'm gonna fix this I'm gonna clean this up and then I want them to stay there so this is my kind of how my cutscenes gonna go so let me fix some of these let's go over here grab our player I'm gonna say that they're at negative three point five one and then I'm gonna scrub through to here and then this is going to be negative three point five one and then scrub through to here and we'll say this is negative three point five negative two point five and I'm doing these exact values so that it's cleaner I'm gonna go over here and we'll say that this is zero tab negative two point five all right cool now I'm gonna stop recording but I need to here let's let's play it so you can see what the issues is going to be it doesn't look right and there's something that we need to do to fix that so if I hit play it's gonna think for a second did you guys catch that the movement is weird and that's because timeline by default when you make this makes the movement all smooth and we want to actually this is it's frustrating sometimes with timeline because you need to like grab things so I'm gonna grab all of these and I did that by just kind of opening this little window here that looks like a curve I don't want to add a key I did this once already good lord so we need to change the tangents can you grab these like that because we want to change the tangents from what they are right now to being linear okay if some of you out there already know how to do this feel free to do it Chuck offsets no if I edit it in an animation window then I can grab all of these right click there we go both tangents need to be linear all right so what I did was I edited in an animation window there when I highlighted everything and I right clicked and I chose both tangents linear and that's gonna make it look less weird and kind of smooth it's gonna make it look more pixely so let's try it now if we hit play let's see what happens see that looks way better alright now the next thing I want to happen is I want the dialog box so so you're going to go down here they're gonna say something so I'm going to scrub to when the players here and then in my dialogue box I'm going to add an activation track the activation track is going to allow me to activate game objects game object that I want to activate is the dialog box and I don't want it active the whole time I only wanted to start being active here and I want it to be active for not forever let's just say - 240 yeah it'll be fine and my dialog box I'm gonna change what it has in it so my text instead of just saying dialogue it's gonna say underwear dad went okay I'm out all right so cool so now let's try this out just go to the game view hit play do you okay and so now that's stuck there our player should probably be up here let's move them up a bit this means I'm like there so this is what I mean making cutscenes is this is just this think you're messing around with stuff let's move all those negative 2.5 s to be negative 1 so here record player negative 1 and then over here you should be negative 1 and there we go you should be fine right cool let's go out a record I want my player to default to be in this position so when I'm not using time line I want my player to be at 0 negative 1 the reason I want that is because when time line is over it's going to reset the player to wherever you have them be in the scene itself alright so let's try this now hit play no wonder where dad went ok so now the time line is done but you can tell that like it stopped they went back because I don't have it hold and I don't have it loop it just stop it's done there's a few issues though if I try to control my character I can see the animations changing but my character isn't moving and this dialogue box stayed up on screen so let's fix the dialog box issue first so in the dialogue box I'm gonna click the gosh where was it here right there we go so if you click on the dialog box itself here post playback state I want it to go inactive so that's gonna make it once we're done with playback it's gonna go back inactive but we still have that other problem and if you're watching this in the future then you're using unity 2019 point 1 you might not actually have this issue because this is a No unity issue where if you're using time line here's what's happening time line is overriding the players animator controller and if I just like jump over here and turn the animator controller off and then turn it back on I can walk again it's it's so dumb it's the dumbest thing ever and it's it's been an issue since twenty eighteen point two we're in 2018 point three I just checked today and it's still a known issue but hopefully any of you who live in the future don't have to do this so essentially what we have to do is we have to not turn the animator on and are off and on again but we need to change what the animator controller is so we're gonna need to make a really quick little script here so in our scripts I'm gonna call this game stuff I'm gonna right click create c-sharp script I'm gonna call this timeline manager and you're gonna have to do this to anything you want to control you'd have to do this if you had enemies as part of your cutscene you'd have to do this to your enemies too so this one is going to work for my specific cutscene but if you want to make it more involve cutscene more power to you but anything that has its own animation controller you're gonna have to do this quick override with it so yeah so timeline manager in order to access the playable director I have to add using Unity engine playable because that playable director is a playable I'm gonna make a couple references here first I'm going to call I'm gonna make a bool private bool I'm gonna just gonna call it fix I'm going to default it to false next I'm gonna make a reference to the player's animator so public animator player animator I'm gonna make your reference to the players animation controller so public I think it's runtime animator controller yep I'm gonna call this player and him because gonna have to cash that I'm gonna have to save it to memory and I'm gonna have to reset it so I need those and I also need the director so public is it yeah playable director and I'm gonna call this director alright cool so in my start method what I want to do is I want to grab the runtime animator controller and I want to save it the one that the player that the player is currently using so I'm going to say player Adam is equal to player animate or runtime animator controller then I'm going to say a player animator dot remem time animator controller is equal to null so I'm essentially turning it off and I'm doing that right at start we could do this on enable and then that way let's actually do it that way you do this on enable and then that way if you want to activate the timeline when you enter a trigger zone so like let's say you have a trigger zone and ontriggerenter 2d you could make the timeline object become active and then it would play the stuff and it would catch the player's animator like you'd want it to so on and abel is probably better than start here so player animator downtime animation animator controller equals no and then in update i want to check to see if the director is done playing so if director dot play I totally forget what it's it's unplayable gosh what is it called he's playing no I'm gonna have to look here director dot I had a weak game object component is it play I swear that's not no that plays it if playable director dog is it played system action no I might have to take a look at my other version here all right I'll be right back no that's what it is okay so if it's director dot state is equal to please state dot playing and I want to know if it's not and this needs to be a double equals because I can't change stuff I can only check if they are any of seelet's come on now what's wrong now operand of type please do oh I should just do if director dot state does not equal I'm dumb sometimes can you do that okay so then I'm gonna say oh and I also this is why I put that fix pool in there I don't want to do this every single frame I'm gonna say and not fix then I'm gonna set fix to be true good large I'm too used to Python right now and not fix I'm gonna say fix is equal to true and then I'm gonna say that the player animator dot run time animator controller is equal to player annum and then um yeah that should be good so I'm going to save this is a dumb fix that I found in the unity forums I love unity but man they they cobbled together everything and sometimes it works really really well other times it's just it's just a pain all right so I'm gonna imply and my players gonna walk down over I wonder where dad went oh come on oh I didn't assign anything before I get too angry I need to actually make sure I'm doing what I'm supposed to - oh he didn't even put the stupid timeline manager script on here all right so timeline manager script I need to know the players animator which is this I need to know the players annum which it should grab from that nope not gonna grab from there all right fine and then director is right there mmm no player Adam doesn't need to be set right away so let's try this now so let's hit play walk down walk right I wonder where dad went and now I can play so now and then I would go out doesn't that I read them don't them to write them them and so on okay so cool we got a little cutscene now next time I'm gonna talk about how you can do that ontriggerenter with cutscenes to create a cutscene when you enter a trigger zone but yeah cool there we go if you have any questions feel free to ask in the description down below you can follow my Twitter to find out when I post new videos enjoy my discord tons are really cool people there and yeah have yourselves a wonderful day you enjoyed this video consider giving a like subscribing to the channel or telling a friend who might be interested also please consider following me on patreon for as little as a dollar a month you can earn access to tangible rewards like early access to videos backer only videos in series holes for future topics streams and even individual tutoring sessions you can find a link to that in the description and as always have yourselves a wonderful day
Info
Channel: Mister Taft Creates
Views: 56,599
Rating: undefined out of 5
Keywords: Unity, Unity Tutorial, C#, C# tutorial, Unity Zelda, Zelda, Action RPG, Unity Action RPG, Unity Zelda Tutorial, Zelda Tutorial, Action RPG Tutorial
Id: Y5RDtN1jM6A
Channel Id: undefined
Length: 24min 52sec (1492 seconds)
Published: Wed Mar 27 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.