Concepts & Setup | Cutscenes [1]

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys today we're going to be working on creating a cutting system so I get a lot of questions about this topic which is totally understandable cutscenes which we can just describe as a scripted sequence of events our Cohen system in modern games they can be great way to illustrate certain actions emphasize or add emotion to a particular moment or develop the plot in your game but actually programming a cutscene system can be quite an undertaking so I'm going to walk you through the thought process of what we need to make such a system now before we begin I'm hoping you already have a basic project set up and are relatively comfortable with coding and navigating in game maker the system I'm going to show you today is going to be using scripts and arrays and I'm also going to be making reference to switch statements and object States so if you're familiar with these concepts then great otherwise you may want to pause and google around or watch some other tutorials before watching this one all right so right here I have a room that I have already gone about setting up and this is just to demonstrate what the cutscene system is going to look like in the end so these right here are two different kinds of trigger objects so the pink one is a trigger that once it's activated a cutscene will start and then this trigger will get deleted and this trigger is actually going to be a permanent trigger so even after the cutscene runs it doesn't get deleted you can run this as many times as you want and this is what the cutscene is going to look like so basically all you would do is just drag in one of these trigger objects and then open up its creation code and write in something like this all you have to do is change this one variable you declare kind of one big array and then in every line of the array we have a different kind of scene so this first one the first thing the cutscene does is set the camera mode basically it sets it to move to an object and then the object I tell it to move to is the Scout then the Scout changes its X scale it immerse the cutscene Waits and so on so this is just an example of a cutscene and this is how simple it is to outline new scenes and obviously there's quite a variation in the number of things that you can do so and then in this one right here I have more events and quite a few scripts that we could go through so I have stuff for fading for changing variables playing sounds and we'll get to these hopefully throughout this little series on cutscenes so for now I'll just run the game and show you these events so we can move as the king right now but as soon as we hit this pink trigger the cutscene is going to start so we have King walk over there's a little interaction here Oh guys so we have moving and creating objects and finally once the cutscene is finished the camera moves back to the player and we regain control and we can move around again so you can also see that the trigger was deleted as soon as the cutscene was activated but if I come over to this one for example if we try to walk on the bridge little guy gets angry at us and we walk away and go on it again the cutscene is going to get triggered no matter how many times we go on to that alright moving on let's jump in and consider what we need a cutscene system to do so we want to make our system flexible enough to handle a wide range of scenes and events so for example moving characters moving the camera playing sounds changing rooms creating or destroying objects changing variables starting dialogue and so on really the list is endless here and even if we don't know everything we need right now it would be great if we could always expand on the system later without breaking everything and we need to consider how the cutscene system is going to work so as I said earlier cutscenes are a sequence of scripted events meaning we have a bunch of actions that we want to perform in a set order so here is just a example of a cutscene so we want to start at that first action and then work our way down performing each of them until they're finished so the problem we need to solve is how do we set up a bunch of code so that it's ready to execute with all the right variables but we don't have it run immediately we only want to run it at that specific time well we can think of cutscenes like state machines for object States so just like we might understand that an enemy objects can be in different states such as idle where it might be doing nothing patrolling where it's going backwards and forwards and attacking but we take a swing at the player we can also have our cutscenes performing in a similar way so instead of states we might call them scenes so we could set up our cutscene like a large switch statement like we might use for states so we could have a variable called scene and depending on what scene is equal to we will execute different code so in the case that it's equal to zero we'll execute the code for fading in and if it's equal to one then we'll move the player over 30 and so on we keep going into that cutscene is finished so now we need to consider just how we're getting from one scene to the other so for example if we're currently fading in we need some sort of exit case that will increment the scene variable causing us to go to the next piece of code and we'll want each sort of action to a different kind of exit case so they'll all be kind of waiting for a variable so for example if we're moving in character we need to be watching to see if it has reached its destination or if we're fading in or out we want to wait until that fade has reached full opacity but in the end they're all going to have to increment the same variable so that we can go to the next bit of code essentially this is all the logic that you'll need to have a working cutting system ideally you'll want to generalize this as much as possible so for example instead of having specific code for moving every time you could make use of some reusable scripts that will handle the movement for you so all you'll have to do is give it for example an object in X and y position and the speed at which it moves and you could reuse that script every time you want to move an object and the same goes for moving the camera starting dialogue and fading in and out so you'll want to make scripts that perform the action wait for their exit case and then increment the same variable so we're starting to get a better idea of what our system is going to look like but at the moment it's not the most user-friendly each cutscene is going to have to require a different objects each with their own switch statements and also changing these cases around or adding new scenes in later can be quite a nuisance because you have to renumber all of your cases so let's consider a different way of setting this out so we know that we're going to have scripts that we want to perform such as a move character script or a setting the camera script and we know that we have some specific arguments we'll want to input into the scripts each time so what we could do is just store all of these values say in an array and then just pull them out when the time is right and input them into the appropriate script so we could have the scripts stored in the first index of the array and then all of the arguments will be in the next positions and now it's important to note here that putting a scripts in like this so just move character without the brackets is different to writing move character and then having those brackets because this code right here refers to the ID of the scripts but this code will actually run the script so if we input this which is the IDE then we're storing the idea of the script and we can refer to this later when we want to run it so there is a function called script execute and it takes in these arguments so the first argument is always going to be the index of the script you want to run and then all of the other arguments are going to be the arguments you want to input into that script so writing this move character object X Y and speed is equivalent to writing script execute the move character scripts and then giving it all those arguments so if we come back to our array that is storing for each scene the script and then all the arguments of the script we're gonna just need to set us out in a way where it can handle any number of arguments but more on that later let's come back to how we're storing the information so we can create an array for all of our scenes so for each of them the script will always go into that first position and then the arguments fill the rest of the array and then when we have all of those arrays we could put all of them into one giant array so kind of having a race within a race almost forming a kind of grid and we could call this this whole array which is storing all of this kind of individual scene arrays we could call this scene information or scene info and then actually use our scene variable from before to access each individual scene so for example if scene is equal to zero then we will pull out the first array which contains all the information for the first scene if it's equal to one then we'll get the second one and then we can just use a script execute function to have our scripts running properly so all this means that when it comes to actually writing what your scene is it'll appear like this you have your scene in for a variable equal to one array and then for each line you'll have the arrays of your scenes and personally I think this is quite an intuitive way to look at it because you can see at a glance what your cutscenes should be doing for all your different actions and this means that we can just create one generate cutscene object and all we have to do is change the one variable scene info then the cutting object will be able to take all this information and just run the cut scene no matter how many scenes we give it and no matter how any arguments are in the scripts assuming we get everything working so let's jump into a project and get to actually coding this alright so the first thing we're going to do is come over to our objects create a new one and I'm going to call this obj cutscene and this is going to be our general object that we create every single time we want a cutscene so we want this to be very generalized so that it will always run whatever information that we give it so the only thing that we're going to be changing about this object is its variable scene information so it's coming to its creative end and we'll just initialize some variables for now sir let's go scene in firm and I'm just gonna say this ax minus 1 so technically we don't even really need to do this right now because the scene information isn't going to be kind of set up in this general object itself we'll be changing this variable probably in the script or the trigger that we use to make a cutscene event so all the information for all of the scenes so remember this is going to be kind of one array storing a bunch of different arrays or all containing information about the scenes we will be changing this later so next we're gonna need scene and we'll set this to 0 for now because this will be the first 10 it will be the first entry in our scene information array and this is also going to be changing as we go through our cutscene to access the different entries now as an example the first kind of script that we're going to be making as a kind of scene is going to be a cutscene wait so for this I'm going to need a timer variable and I'm just gonna set this as 0 for now next let's come over and make that script so in our scripts don't worry about these finales just a couple things I have set up to illustrate later so let's make a new script call it cutscene wait and let's just describe this script here using the description so if you don't know about this this is just a way to get some information about your script to pop up just like other scripts too so for example we can type our seconds and now if we type in cutscene wait if we wait for a second it should come up in the sort of disagree but here telling us what arguments we need to input into the script so now what you have to imagine is that whatever script it is currently kind of accessing from the scene information is going to continuously run it so every single step of the game so every step of the gain for the cutscene wait I am going to increment the timer variable and then of course we need the exit case or the finished case for this particular scene for the waiting so depending on what this argument here so argument 0 of the script is equal to how many number of seconds we've set it to wait for so if timer is larger than or equal to the number of seconds but we have to times it by the room speed because of course this is going to be if we just left it as argument 0 and for example we said 4 seconds it would go off after 4 steps but to get the number of seconds we have to times by the room speed which is probably either 30 or 60 in your project so if the timer is larger than whatever however many number of seconds you said that is going to be the exit case so what I'm going to do here is have timer equals 0 and of course we want to increment the same so this will make scene go from 0 to 1 or whatever it's up to but actually instead of writing scene plus plus I'm actually going to take this create another script call it cut scene and action and I'm going to put it in here and the reason for this is that we're actually going to change what it does later on but we're not going to want to update all of the scripts from scene plus class to whatever we change it to so this way we can just change it in one place so coming back we're just going to write cutscene in action now for testing purposes I've actually created another kind of demo script that we're going to use for the cutscene called create box at Mouse this is probably not something you're going to be doing but it's just to test it so I have an object called obj box basically this is just a blank blue box that is going to be created whenever I press my mouse button so this script unlike the white script it's basically going to keep running and it's going to keep checking if I press the mouse button so it doesn't take any arguments it really just waits for some kind of input and then when it finds that input that is going to trigger the end of that scene so we're going to go and create a box and then we're going to end the same just like before with our wait all right so say in our obj cutscene what I'm going to do is set up a scene and to do that we will just type scene in for equals so this is a way of declaring an array so you can do it just like this normally and then you'd have your entries but you can also do it over multiple lines and you can even put the entries themselves over multiple line which is exactly what we'll be doing but instead of just numbers remember we're actually going to have arrays within arrays like that so for the first one let's just say that we're going to wait for an input to create a box at whatever our mouse position is I remember that one doesn't have any arguments so all we do is store the script for our cutscene wait I say that we're gonna wait for two seconds so what we would do is just comma and then write the argument - and then let's say we can create an at the box then we wait for seconds and then it's going to let us create another box and then that will be it so that is going to be our cutscene let's have a think about how we're gonna get this to run so like I said before in the step event what we're going to do is make use of the script execute function so now what we have to do is pull out the appropriate index so it's asking for the index so this is going to be the kind of name of the script so we're gonna have to depending on what scene is grab the array from seeing infer and then grab the first entry in this array so first off let's grab the current scene array that we're on just like that and then we can get current scene and in the first entry in the currency right so that will be getting this and now this is where we're gonna run into our first problem right so for the crate box at Mouse it only has one argument so this will run just fine if we have it like this but when it comes time to running the cutscene wait this actually needs to have another argument so we would actually have to go and put current scene 1 because this is how you put in the additional arguments for this function so depending on the number of arguments that we have we're gonna have to do this differently so we're actually going to have to get the length of this array to get the number of arguments stored in that entry and the way that we do that is just get the length of the array and then minus 1 because for example the length of this array is 2 but the number of arguments is 1 so that would look something like this so we would get the length of the current scene all right and then depending on what that is we could use a switch statement and then depending on the length of this minus 1 in the case that at 0 we just run the script and we don't do anything else in the case that it has one argument then we input that one argument and we keep going and to be honest there isn't really any way around this and you'll need to keep going down like this creating a lot of cases if you have scripts that do have lots of arguments and you want to be safe but for now we'll just have those so if we just drag this objects into our room so I've just set up an empty room that basically has nothing and we drag in our cutscene objects and run the game we're sure to have our cutscene running so remember what it is doing right now is just waiting for our input of the mouse so it shouldn't be doing anything else and then as soon as we click it's going to direct us to wait and we can't do anything else we won't be able to create any objects and it's gonna keep going like this so let's see if this works oh it's running let's click though your eye click it's not going to create anything else now after 2 seconds are up we should be ready to create another one there we go and if I click again it won't let me create anymore for 4 seconds and then finally the last one there you go and it's the end of the same so now this error is going to be popping up because it is trying to access the next entry in the array but it doesn't exist so we're going to actually need to take care of this we could have for example in the cutscene and action hey check to see if the scene is larger than or equal to the array array length 1d of the same information - one because the arrays start at zero and the last actual entry there will be so for example if the length is 2 then the last entry is actually going to be entry 1 because the first entry is 0 so 0 1 makes 2 entries so if that's the case then what we want to do is destroy the object all right so that is the basics of what we have to do to set up our cutscene object next time I'm going to go through some more examples of scripts that you can use and also refine this system a little bit so that we don't have this quite ugly switch statement here thanks for watching guys that's it for today so today's topic on cutscenes was actually chosen by a vert on patreon so thank you to everyone who voted and thank you for supporting me to create these tutorials some special shoutouts to Sami myth Alena s Riki see Ian second tin Daniel Hargrave max Mullin are hunter T Thomas M the great poultry XT game studio Doe in tech Ben and Spock 2018 I hope you guys are well and I'll see you in the next video
Info
Channel: FriendlyCosmonaut
Views: 33,881
Rating: undefined out of 5
Keywords: cutscenes gamemaker, cutscenes tutorial gamemaker, cutscenes gms2, cutscenes tutorial gms2, cutscenes friendly cosmonaut, how to make cutscenes gamemaker, cutscenes gamemaker studio 2, cutscenes gamemaker studio
Id: 2CLm38HCP64
Channel Id: undefined
Length: 19min 48sec (1188 seconds)
Published: Fri Mar 02 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.