GameMaker: Studio - Movement Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
alright guys welcome back now that we've covered the very basic fundamentals of using game maker what we're going to look at over this next series of videos is how to make your first actual kind of playable game so we're going to be looking at making a very very simple top-down scrolling shooting game the first thing we're going to be looking at in this video is player movement so how to move the player object like left and right the different ways you can do that through code through drag-and-drop and all that kind of stuff so that you can decide what approach is best for you in your game and hopefully you'll learn a lot so as you can see I already have my player object set up here in the middle of the screen and if you don't have any idea what objects are or how I got to the stage please watch my last video on game maker basics that'll teach you everything you need to know just about this is very basics about how like sprites backgrounds objects work and so on so forth so if we go into our player object over here the first thing we're going to look at is how to move left and right through through the drag-and-drop system and then I'm going to explain it through code I did walk through it a little bit in the last video like the sort of basic elements of it but we're going to try and sort of walk through in a bit more detail and explore what all the kind of different options you have here what they all strictly do so that you have a good idea of all the different sort of main ways you have to implement movement in your game and you can decide what's best for you okay so the first and easiest method of doing left and right movement in in the drag-and-drop system is to go to events add event we're going to want to make an event for when the player hits the left key or hits the right key or whatever controls you haven't a want and the basic way we do that is go to keyboard and I mean we could hit left here or we could hit right here or we could go to like others like letters or whatever or whatever control you want to set and depending whatever controls your game is using we're just going to use left and right for now so if we go to keyboard left now as I explained before this event up here called keyboard left will will trigger whenever the left key is held so like every single four rain of the game it'll check to see if the left arrow key is being pressed and if it is it'll run these events over here so the actions we want to take are obviously now to move our character to the left so what we want to use here this very simplest way of doing this is not actually to use these move fix things it's to use a jump command this this arrow arrow pointing to the dot over here is the jump to position action so if you drag that into actions you'll get this little dialogue up here what this means is we move directly to a specific position on the screen and if we take this box called relative at the bottom here what that means is that these coordinates are relative to the object and not to the room because obviously if we set lay if we turn this off and we set this to 0 0 0 0 as a coordinate is like the top left of your room so that would mean whenever you have left the character would just walk to the top left of the room that's not what we want to happen we want to move about 3 pixels to the left of where we were before every frame so we want to tick relative so our movement is related to the object when go to X and we want to say and because you know left is lower and right is more in terms of x coordinates we want to say -3 so I want to move 3 pixels to the left ok and then obviously we want to do the same thing the other way around so if we go to do this again go to keyboard add keyboard right and then do the same thing again jump to position relative X plus 3 ok now if we hit OK and we run that hopefully all going well which it has eventually there we go we can now get move left and right you can see the kind of movement this creates for you it's very very specific straightforward method of movement because you are literally moving 3 pixels every frame that the game is detecting a left or right input so that's that's literally the simplest way of doing so another way to move left and right using this is to use these moved move commands up here so if we get rid of these now and we go to left and we use a move move fixed with these arrows on and we're moving to the left till we want to take the left direction and we set our speed to three this is slightly different the way this works is different let me just set the right direction up exactly the same I have to put minus in here because we're just setting an absolute speed in a certain direction so speed three going that way the way this is different though is this sets a speed that doesn't go away well whereas before what we were doing was moving the player object by a specific amount every frame this is setting your speed to be a certain amount and your speed is add value that moves your object every single frame by itself until something makes that speed go away so that means once we start moving we're not going to stop until something causes us to start moving which if you a basic understanding of Newtonian physics will sound kind of familiar to you and so what we need to do is we need to create a force of friction what that means is the force that slows the object down after it's started moving and causes you to come to a halt so if we go to our events and go to add event on creation so that means when the object has just been created and then this little icon up here with the arrow turning into the smaller arrow is our set friction action so what we typically want our friction to be a very very low value it literally something like naught point like not v or like maybe even less maybe a little bit more test that value we'll see how that works but I mean the reason you this is a very small value is because what friction does is friction literally reduces your speed by this amount every single frame of the game while your speed is not zero so if your speed is like minus two and your friction is say 0.5 it'll go from minus 2 to minus 1 point 5 to minus 1 - no - not 0.5 to 0 like over the course of like 4 frames whereas like if your speed was - it would go from 2 to 1 point 5 to 1 - no point 5 to 0 you get the idea so if we set our friction to null point 5 and left and right set is our speed to about 3 and we compile again and then we have it we should be moving left and right and now if I just tap the key I start moving at 3 and then the friction causes us to slide to a hole it's a little bit slightly at the moment because you know you can play with the values to get it to stop so more firmly or more on point so this is sort of a looser more sort of analogue method of moving about so that's how we move with the move fixed command however what we are still doing with our move fixed command is we are still setting our speed to be a specific value as opposed to slowly accelerating to that speed as you know you might want for however you want your game to feel so you might want to slowly move up to a speed as opposed to sort of instantly selling yourself to move in a specified speed so in order to create acceleration instead of just sort of you know stank a movement value what we need to do is if we go to these actions and we take this relative box again again what this means is we're setting the speed to basically be three in this direction relative to what your speed currently is so what kind of adding three to your speed as opposed to we're adding a speed of 3 and the left to your current speed as opposed to just setting your current speed to be 3 in that direction of course 3 would be way too much to accelerate viable so we're going to set this to 1 and left and and the right we're going to be the same thing 1 and relative and now this would go absolutely nuts um because we at the moment we would accelerate left and right by one constantly and the friction is still the only thing slowing us down so theoretically if we hold left for like 10 frames we're already moving ten pixels a frame to the left so we need to establish a maximum speed this is where things get a little bit more tricky but not really by all that too much so I'm going to go to events go add event and we're going to look at the step event now the step event is I think I explained before is literally an event that just triggers every single frame so every single frame of stuff in this this action thing will happen to this object so what we want to do here now if I can find it is test here we go test variable little circle circular type var thing with the word var in it so what this is is we're we're asking the game a question right now we're going to ask if the variables speed which is so as you might have guessed represents is the variable that we've been saying numbers to with those actions and our left and right event so we're going to test if speed is greater than six so in either direction like it doesn't matter what direction you're in if your total speed of your of our object is greater than six we will carry out any actions that follow from this this action so if speed is greater than six that's all that's the first action we're doing in our step and after that if the speed is greater than six what we want to do is set speed to six so what that means is if you would go above six so like the game is trying like to move you at six point five or just trying to move you a seven or whatever we just settle speed back to six so that that basically imposes a maximum speed we can be below that but we can't be above that and that's in either direction so if s B is greater than six set variable speed to six now we might want to turn off friction up a little bit because how it was before was a little bit slide II so if we tunnel friction up to two point two so that we hopefully get a little bit of a better slide to a stop let's see how that looks yeah as you can see we're now accelerating to a speed of a maximum six and then when we let go of the burn we slowly slide to a halt so we slide stop and we slide to a halt that's how you can create a kind of more sort of sliding fluid movement the tio character obviously it depends exactly on what kind of failure you're looking to create in the end but those are the sort of two main methods of moving your character around you're either jumping to a new position every frame based on a based on a value that you want your player to always move on so just add like five to your ex or whatever to keep moving like five pixels a frame or what you're doing is you're creating an acceleration every time you're holding left or right and then creating a maximum speed you can reach and then creating a friction that slows you down when you're not pressing those buttons I mean this little extra variance you could do in between so you could have it so that when you you're moving like this every time you're not pressing one of those buttons you were instantly like lose all your speed you could just set your speed to be zero so like if you want be able to come to an instant stop and you don't want this kind of sliding effect that we've got going on then you could do that as well if you still wanted acceleration but you didn't want friction you know you can use you and mix and match until you create the feel that you want to feel the feel that you want to feel well yeah I guess that makes sense
Info
Channel: Shaun Spalding
Views: 331,817
Rating: undefined out of 5
Keywords: Game Maker (Video Game Engine), Game Development, Indie Games, Indie, Games, Tutorial, Information, Learning, Tutorial Series, Game Maker Studio, Steam, iOS, Android, HTML5, Windows, Making Games, How to make games, Basics
Id: 9drRR2jE4lE
Channel Id: undefined
Length: 12min 27sec (747 seconds)
Published: Sun Dec 02 2012
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.