How to Make an RPG in GameMaker Studio 2! (Alternate Part 1: Player Movement and Collision)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello there welcome to this little series that i'm doing that's going to show you how to make the game that you see on the screen right now this entire thing is going to be covered in just six parts and there is an alternate version of this first video that's a bit longer and explains more about game maker itself and how basic programming works and that video is 100 beginner friendly it is specifically for people who've never even looked at game maker before so if you are a complete beginner and you just downloaded game maker studio for the first time you can start with that video as your part one of this series these part ones are gonna focus on making a player that can walk around and collide with walls it's actually a really really simple process and it only requires i think less than 20 lines of code so i guess without stalling any further let's just uh get up and go it's gonna be great first things first let's go to our room so we can set our viewport and camera properties so go to the bottom left down to viewports and cameras enable the viewports viewport zero make sure it's visible if it's not checked already and i picked some values that i think look kind of nice for this project let's go with 288 by 216 and for our actual viewport we are going to do 864 by 648 which is three times larger than our camera so our viewport will take up you know just a decent size of the screen okay cool that's uh all we're doing for this room right now we could act well we could actually go ahead and resize this room to match the uh size of our camera is a good idea so let's go 288 by 2 16. okay let's get out of here and now we're going to make our player object and our wall object for the player to run into so first let's make some sprites for both of them we're going to right click create sprite open up this first frame here and we're going to resize this image it's 64 by 64 right now we can resize that to 16 is good size so 16 by 16 pixels apply that and we're gonna make our player red and that's all we're gonna do for that for now let's change the name of this to sprite player good good let's make another new sprite again let's make this 16 by 16. apply that and we're going we're going blue for this wall exit out of here we're gonna name it sprite wall pretty good so now we are gonna create our player object and our wall object so let's just go ahead and name this obj underscore player and select our player sprite for that i'm going to come back over here create another object you are going to be obj underscore wall with our wall sprite now this is all we're not going to need any code in the wall so we can actually just go ahead and exit out of this this is this is done let's go back to our player add ourselves a create event so let's set up our variables for the speed of the character so we'll start with our x speed which will be used to move our player left and right y speed will be used to move our player up and down and then we'll have a variable called move speed which will determine just how fast the character can move overall we'll just set that to one so let's add ourselves a step event here now the first thing we're going to do in our step event is make some variables that will store the values of whether or not our arrow keys are being pressed and to do that we'll set the variable right key equals keyboard check vk right virtual key right so this function is checking for whether or not a button on the keyboard is being pressed and it's checking this value which is the right arrow key and so now this will return whether or not it's being pressed let's also go ahead and repeat that for up left and down okay so as you can see i have up key which checks for the up arrow button left key which checks for the left and down key which checks for down now we can use all this stuff to calculate how our character moves so let's go down here i'm gonna make a comment out and say get x speed and y speed to make a comment you just do two forward slashes and then this is not a line of code it's literally just something that you can mark for yourself so i'm just noting that this is what i'm about to do under this the way we're going to get our x speed is by figuring out the difference between our right key press and our left key press so let's set that up like this x speed equals in parenthesis right key minus left key and then this value times our move speed variable so what this is doing is this is just checking what direction we're going in and it's doing that by saying if we're pressing the right key this will return one and if we're not pressing the left key this will return zero so we'll get one minus zero times our speed which currently is one so this would return one now if we weren't pressing the right key it would be zero and the left key if we were pressing that it would return one so we'd have negative one times movement speed which would be negative one which means our character would move left once we're actually adding this to our x value so we can do the same thing with our y speed and to make sure that's going in the correct direction since in game maker as you go to the bottom of the screen the y value increases and as you go to the top of the screen the y value decreases we're gonna have to start with down key minus up key and then that times our move speed now to actually make the character move we just have to add these values let's say move the player we just have to add these values to our built in x and y variables so x plus equals xspeed and y plus equals y speed which is how you would add it every single frame cool so now our player would move uh we can go back to our room go to the instance layer which is an instance layer is where you would put objects select our player press alt to put it in the room and we could actually run this and have the character move around alright nice let's get to the collisions with the walls so back in our player step event to calculate collisions basically what we're gonna do is check if there's a wall in the way and if there is we're gonna set our speeds back to zero before we add them to the players which means our collision code is going to need to go in between getting our speeds and then adding them to the player so let's say here are collisions so for our x collision we're going to say if place meeting x plus x speed y with object wall [Music] we will set our x speed back to zero so we're checking in the direction that we're moving by adding our x speed here to this value and we're checking for it running into a wall which is what this function does and if we would be running into a wall we're going to set our x speed back to zero so we don't run into it and like clip into it okay uh let's do the same thing with the y speed and to do that we would have to do y plus y speed and we have to make sure that we're setting y speed back to zero just make sure you're putting all this stuff in the right place so that's it for having our player run into stuff now we can go back into our room again go back to the instance layer so we can actually put some walls down let's set our walls all around here you can place them individually like this or you could place one and you could stretch it so let's do that let's do that a couple times that's a good level all right let's try it out okay so we're moving and we're running into stuff everything's all cool all right if you're having any issues just go back and look at the code and make sure you you got everything written down properly uh yeah so cool we did it this is functionally basically the most important part of making a little rpg like this so now we can move on to character animations okay so first video down if you have any questions about anything there's a comment section you send me a message on twitter or i have a discord which is for my game and if you just kind of happen to find this video then yeah check out my game rosa starcross there's a free demo there's a trailer for that on this channel but uh yeah part two is going to be focused on actually getting some animations on our character which is going to be super cool but uh yeah i guess that's it for this first one good luck and keep on trucking [Music] you
Info
Channel: Peyton Burnham
Views: 28,929
Rating: undefined out of 5
Keywords: gamemaker, yoyogames, rpg, how to make, how to make an rpg, gamemaker studio, gamemaker studio 2, gms, gms2, tutorial, beginner, beginner tutorial, undertale, omori, top down, pixel art, indie game, how to make a game, rose of starcross, earthbound, platformer, rpgmaker, rpg maker, pixel, from scratch, deltarune, delta rune, easy, coding, code, programming, cute, animation, player movement, collision, parallax, player, depth, tiles, tileset, tilesets, camera, room transitions, warp, rpg tutorial, nintendo
Id: DqAcvriW5Pw
Channel Id: undefined
Length: 10min 12sec (612 seconds)
Published: Thu Mar 25 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.