GameMaker Studio: Drag & Drop Platformer Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
alright God is how we doing this week what I'm going to be looking at is some well basically I've been a little bit worried that maybe I've been leaving some people behind that I've been jumping a bit too far ahead with all the kind of advance like GML coding kind of stuff and like if you were following along just using the drag-and-drop options you probably got left behind somewhere in the in the top down shooter tutorials so I'm gonna go back and just basically explain how to recreate the platformer from like my index platformer tutorial or how to recreate something mostly similar mostly the same sort of thing just using the drag-and-drop commands in case you know you know you're not really ready to get straight into the code yet and oh you're just you know you're trying to make up some quick prototypes and stuff for your game and you're not you're not looking to create anything that's super complex or polished or whatever you know right away which is perfectly fine so I'm gonna just be taking a look at how how we can still use you know all the drag-and-drop options use some of the ones we haven't used yet and that kind of thing and you start to see how you know you can build things like a platformer with it so as you can see over here we've got a got the setup that basically what I started with for um my in-depth platformer tutorial which you know once you're more comfortable with the code um you know once you you're prepared to step into coding you know you can go go watch that and see how you know you can take direct control over these sorts of things but yeah we basically just have the same setup that we have in that tutorial um we have a sprite for our player a sprite for the balls and an object for the wall and an object for the player with the sprite setup as shown and I've just sort of scared that around not onlys have any code in them yet whatsoever the a totally blank so I mean if we were to run the game right now all that's going to happen is No right so these just sit here nothing's going on so one thing we're going to want to do is because we want to use these walls we're going to take this box over here called solid which basically turns on some sort of automatic kind of like collision system um within GameMaker in it that tells the game that this object is a solid wall and we'll be using that in a little bit so the very first thing we want to do is make it soo our player actually Falls and there's some gravity in the scene so what we're going to do is now what we would normally do I suppose what a lot of people would do is a normal valid ways of making this work is do something like go to create and use set the gravity to set up a gravity you specify the direction of down as being like 270 foot down and you know give yourself a gravity that way I don't like using this gravity the reason why I don't like using gravity like this is because gravity the built in version and GameMaker it operates by applying a speed a vertical speed to your character every single frame and it does that after your step it then which I don't really like the reason I don't like that is because you can do all your speed calculations in your step event and do your collisions and work them out all properly but you have to basically every time you land on the surface you need to turn this gravity back off whereas I prefer to have my gravity system on all the time and you know let you know as it is in reality and you know I never actually need to turn it off because if you don't turn it off you know you do all your speed calculations and stuff and you you say right collide with this wall and start moving and you stop yourself moving you set your vertical speed to zero but then your gravity is applied after your step event so you start to fall into the floor so if you've ever tried to just mess around with the actions and stuff and set up gravity and you know build collisions in what would seem an intuitive way you notice you're player always just constantly Falls really slowly through the floor then you know now you know why it's because gravity is applied after after the step of then which I don't like we can create an equivalent of gravity super super easily without using creative and all we need to do is create in the step of then use this action over here which is set the vertical speed and if we set on to relative it'll just add this vertical speed on to our current vertical speed every single frame in other words it'll do exactly exactly what gravity does so if we just set the speed on or point six or not point nine six yeah that'll do that will you know apply vertically every single frame if I run the game now you'll see I'm falling falling faster and faster and so on Newton is a bit slow one point six we'll try that maybe might be a bit fast well as fast but you get the point yeah so basically that set the vertical speed relative and a small number in here does the exact same thing as saying the gravity only it happens exactly when you tell it to and it doesn't happen like after you're just ever bent and stuff like that so without actually coding that you know and that gives you a little bit more control over you know when your gravity happens just slowing you're creating a game logic you don't have to turn your gravity off you can just set your vertical speed to be zero when you're on our floor or something you know it just makes things like that a little bit easier alright so now that we have some gravity for a player the next thing we want to do is make it so he actually lands on the floor in order to do that we're basically going to check every single frame to see if just below is an on line actually sorry we're going to check to see if the place we're going to be next frame vertically if there is a collision there so if we were moving up we would check basically a little bit above us and if we were moving down we check a little bit below us to see if we're about to have a because and I explained this in my in-depth platformer tutorial how you want a handle collision logic generally or how I most prefer to handle it you don't have to handle it this way it might not be the best way you know I don't know everything but the way I prefer to handle collisions logically in my head is to say if I am about to collide with something move as close as possible to that thing but don't but stop just before I would collide with it and set my speed to be zero how a lot of collision systems might work is to say if I'm currently colliding there so I've I'm already overlapping the object push me back out and I don't like that I don't I don't like to create a system that sort balances you out of an object when you've already collided with it I prefer to stop the collision from ever technically happening in the first place by saying if I am about to collide with this object then move as close as possible to it to land on it and then you know set my speed to zero so that's what we're going to do over actions as soon as I can find it this one over here in control a little arrow pointing towards a little white line sideways not to be confused with a different one that we'll use in a minute which is an arrow pointing downwards still white light so the arrow pointing to the right or this little white line drag that over here this is our check collision action so what this does is what I just said it's going to check a given set of coordinates to see if there would be a collision with our object if our object was at these coordinates would it collide so what we're going to say x and y to be zero and be speed so what that means is it's going to check on tic relative at the bottom here so these are related to our current X Y coordinates so what that means is it's going to check X a relative zero so exactly horizontally on the screen exactly where our object currently is so whatever my objects x-coordinate is and whatever our y-coordinate is up and down on the screen in plus whatever our vertical speed is which is represented by V speed you'll know if you've seen me doing code and stuff now you'll realize from this that you can use the built-in variables in the actions like this but if you type V speed into here well that does is will pull your objects vertical speed out and it'll it'll basically ask ask the game for your current vertical speed which we already set with our like gravity and stuff is what we're adding to that's how we get that number so so if we were falling at say four pixels a frame what this will do is it'll check our position and four pixels down from that position it's going to check there to see if that would be a collision objects stick only solid so it's only going to check for things like our war which are set to solid and then hit OK now you'll see these little sort of you know circular actions like this which are questions and link so they're you know they're asking the game a question that they're checking to see if something is true basically if that collision is true then it's going to carry out whatever the next action isn't here so if I were to do something like create an instant I mean since there's no reason why we would do this but like if for example like you know we check if there's a collision then create a wall somewhere this is just to make an example we don't obviously want this piece of code is that it will say if there's a collision there then do this and then if we have more actions underneath it's not going to say if there's a collision there do this and this it's just going to say if there's a collision then do this then regardless do this so it'll only do it will only do the next action by itself if we want the question if it happens to be true so you know if there is a collision here if we want to do multiple actions which we do we need to go into control and use these arrows here which create a start of a block and an end of a block and these allow you to group actions into one well block so if we start to put our actions inside just by dragging and dropping and it'll say if there is a collision at position and start of a block and then it will do everything until it sees end of a block if that happens to be true and if it's not true it'll skip this block and we'll do or whatever happens to be underneath it so remember if you are asking a question if you're doing the question sort like a circular drag-and-drop action icon then if that question is true it returns true or any way you know that is a collision or you know if there is a certain number of instances or you have pressed a button you know and so on so forth it will create it sorry it will do whatever the next line is unless you use blocks in which case it'll do everything inside the block that follows it so now that we know whether or not there's a collision obviously we don't want to create a wall it's just an example what we want to do is as I said move as close as possible to the wall that we would collide with now there's actually a drag and drop operation built specifically for this you go to move over here the little downward arrow I mentioned it earlier pointing to wall to white line that's the one we need now you drag that into your block and it's called move to contact which means it's going to move your object as close as possible without to the object without actually colliding with it well it's going to move it in a given direct yes is going to move sorry this task is going to move your object in the direction that you set here until it collides with an object so basically we're going to say move to contact in a direction direction oh what that means this is gonna move us in the direction that we're currently facing so like so if movingly get a little bit diagonal and stuff it or whatever basically if it's we're just going to move in whatever direction we're currently moving which is appropriate since we checked if vertically we're gonna hit something we're going to set the maximum just to be 5 because there are some other little bugs and quirks of this system if you have maximum or minus one would basically mean that there is no maximum and all new viewers as close as that needs to but there are a few little quirks and eBooks because we're using the direction of direction and sometimes if you like walk off of a corner you can seemingly teleport you to another war so just to sort of ward against that again this is sort of just a little prototype engine for you really it new it does have a few little quirks and then go better though if we set maximum to 5 it shoot me more or less get rid of those little kinks and then again solid objects as we said so it nervous to find our or object wall you know basically movers a maximum of 5 basically just put whatever your current your maximum speed happens to be we don't actually have one set with our vertical speed technically how gravity can go on forever but typically you would set something up to limit your speed too young or ridiculously fast ever and then your maximum would appropriately be whatever that happens to be so move the contact in direction direction then the next thing we need to do also moved as close as possible to the wall vertically or the ceiling is to basically reduce orbital speed to zero because we've hit the wall so basically we just use this the big white dial error again we're just setting a vertical speed we don't need to take relative this time and just have zero so it'll just settle vertical speed to absolute zero and now hopefully if I run the game can you can see boom we land on land on the floor it was a bit quick but hopefully you can see that it just Landers boom on the floor because it he moved faster and faster and faster and then he saw he was about to hit the floor he moved as close as possible to the floor on a pixel perfect look and and then a speed has been set to zero so now he lands on the floor that's fantastic the next thing we want to do is basically set it up so that he can collide horizontally as well as vertically basically we just do exactly the same thing we've already done so but we use H speed and stuff in horizontal speed to to do our checks so again if we go down to control and we do a check collision and we're going to say applies to self and we're going to just say X H speed Y zero relative objects only solid all the same reasons as before but instead of we're checking exactly where we are vertically and we're checking exactly where we are plus our current movement speed either right or left so it'll be like minus four if we're going left or plus three if we're going right you know it's going to add that number is going to check that position the position we're about to be in next frame to see if there's a collision horizontally I got those in the right order yes I am I'm putting this one above the vertical check there's a reason for that the reason you want to check horizontal speed first in terms of likely or logic order as opposed to vertical speed is just for the odd case where like say you hit a perfect diagonal you want to say like in like if you were falling toward the platform and like you're about told you about to move into it perfectly diagonally you basically have to make a decision in your game about whether they're not whether or not that means you land on the platform or whether or not that counts as hitting the wall and falling and obviously it feels a little bit better to play if you say you land on the platform which means you want to check your horizontal collision first because it's going to see oh there's nothing in front of me move me horizontally and then check below you and say oh there's a floor below me land as opposed to if you do vertical first because it would say oh there's nothing but we move vertically olders now a wall in front of me don't move horizontally and you would miss the platform so that's the only reason why I'm going to do horizontal in front of vertical so now we've got a second collision check setup or what we want to do is just create another start block and another end block right then just so that we can create some actions for what happens if we're about to collide horizontally and then again we just do this the same thing we'll go to move and we say move to contact a direction direction maximum of five and against solid objects okay and then we want to set our horizontal speed to be zero simple as that and now it'll be move that to that there we go the thing we want to do now of course is set up so we can actually move because at the moment we can't actually move left and right so there'd be no way to actually demonstrate that this horizontal speed is even working so in order to set that up I'm going to come over here and add an event for keyboard for whenever the left arrow key is pressed now when the left arrow key is pressed what I'm going to do is I'm going to take set our horizontal speed e - naught point five and we're going to say that that's relative so it's going to constantly add negative nine point five to a horizontal speed whenever we're holding left so at the moment we can speed up to infinity obviously not what we want so I'm going to give ourselves a maximum speed I'm going to do that as I'm going to go to control no I'm not yes I am and grab this question mark over here and it's going to say if an expression is true now this is quite powerful action that allows you to check like any like variable and looking in the game or whatever to see on a check check like any like mathematical function if you values like Excel and you've done sort of like an if statement or something in Excel to see like if like B 22 is bigger than you 29 then color the cell green or whatever it's that same sort of concept so what we're going to do is we're going to say if H speed which is a horizontal speed is greater than minus five so if our horizontal speed is bigger than nine is 5 which means like it could be minus four or it could be zero or it could be like three if you're moving to the right or whatever and then because we've got that and as I explained to you with a circular icon over here how this works is it's going to say if that's true then do this thing and if it's not true it won't it won't do this thing if we wanted it to do multiple things again we would use like a start block and an end block and put a bunch of actions in but we don't we just want to do is one thing so you know that should be perfect we find out and hopefully if I run the game we should demonstrate like I've landed on here and I can move to the left and collide with that wall so we're getting there okay we've got gravity and we can move to the left and we can land on platforms we're almost there so what we want now is just I'm going to copy and copy what I've just done and basically just do the same thing for moving right so I'm going to test an expression again and say if I hate speed this time is less than five because five horizontal speed whoops beam is moving to the right at five pixels a frame or whatever so if our horizontal speed is less than five then and and the reason I'm doing this expression is testing this expression is to set a maximum speed so when we're moving to the left we can't go more to the left than minus five pixels the frame and when we're going to the right we can't go more to the right than five pixels a frame because it has to be less than five so then we're going to go to move set horizontal speed and we're going to set that to not 0.5 relative if we press right same as what we did for left only is positive instead of negative now we can move left and right fantastic and you'll notice you slowly speed up as well like like that the moment you slide infinitely if you let go of the button so what we're going to do is go add event create and we're going to add and you'll be familiar with this if you've seen any of the coding stuff as we're going to use set friction which you're sets up a value that will reduce our speed every single frame and we're just going to set that to be something really small and more point not to and then hopefully I won't move left and right okay we could do a turning that up a bit maybe not point to there we go so now when we move left and right we slowly kind of slide to a hole it's very very slide II at the moment there were a kind of a Mario feel but um you can play about with those numbers to get a feeling exactly kind of how you want so yeah so now we're setting off friction what we want to do now is be able to actually jump so we can climb around this platform level so what I'm going to do is go over here and add an event this time I'm going to use a key press event instead of just a key event and say shift just so that when we're hard you know we don't jump by holding shift we jump by it by pressing shift so use press shift so it only detects it once when we first press it and only carry these kind of things out again if we let go of the button and press it again now what we're going to do is just set our vertical speed to be minus minus eight for example it's - because we're going up if it was positive it means we're going down we're just going to set that to be like minus eight so if I says now and I press shift you'll see were able to jump that's pretty cool but at the moment there's nothing stopping those mashing shift and just jumping you know forever drumming in the air so we need to say that we can only jump when we're on the ground and the way to check were for not around the ground is to basically use a collision check like we've been doing in here and we're going to go to control and say in questions drag this check collision action and we're going to check X we're going to say relative again so at the moment this means this being zero means it's checking exactly where we are but we want to take just below us I'm going to check one pixel below as y1 exactly one pixel below where we currently are to see if there is a solid wall only solid so if there is we should be allowed to jump and if there isn't and we won't get a jump so now if I run the game press shift and hear me mashing it there but you know I'm not not floating off into the sky so there you go there's a functional system for making our platform a simple platform little engine game whatever you want to call it in using just the drag-and-drop actions that could well be a few little bugs and quirks with it and stuff I haven't you know super leaf thoroughly tested it or anything like that you know it's not my area of expertise I don't use the drag-and-drop options a lot but hopefully there i've been able to sort of show you kind of a bit more about how they work and how you can use them a little bit more complicated ways because they are still useful and they still you know do give you a lot of power flexibility and all of that and then when you know perhaps navy later down the line you're ready to move on to you know learning some scripting and learning a little bit of code you can look at my in-depth platformer tutorial which shows you how to create basically everything we've created here but step-by-step explained line by line through the GML code entirely up to you now the choices there so yeah I hope you guys totally enjoyed that I have a Facebook page now where you can keep up with the reasons why all my videos keep getting delayed and and all sorts of fun things like that and any other fun awesome things I haven't be doing or anything like that you can follow it on a Facebook page so that I don't have to blather on at the start and videos about stuff I can blather on the Facebook page and those that care can read it that awesome ha just in another awesome rhyme awesome yep so that's everything for this week I hope you guys found that super useful and I will catch you guys whenever I catch you guys probably next week yeah I'm gonna say next week see you guys next week in a bit
Info
Channel: Shaun Spalding
Views: 204,709
Rating: undefined out of 5
Keywords: Game Maker (Video Game Engine), Game Development, Indie Games, Games, Tutorial, Learning, Tutorial Series, Game Maker Studio, Steam, iOS, Android, HTML5, Windows, Making Games, How to make games, Basics, Simple, Platformer, Easy
Id: QsfSbHrA7uY
Channel Id: undefined
Length: 26min 56sec (1616 seconds)
Published: Fri Mar 29 2013
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.