Right way to do Jump in platformer game in GameMaker studio

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi i'm knight ansaria in this video i'm gonna show you how your player can jump in the right way okay so your code will be more readable so without any further ado let's begin you remember from last video we create three function one of them for input checks one of them for movement and one of them for apply gravity and we did create an script to write all of those code in those function if you didn't watch my last video about platformer just go to my youtube channel that you are in right now and um go to playlist and in there there is a playlist that all of these video for this platformer game is in there we're gonna do the jump so what we should do for doing the jump first of all we should check the input so whenever they hit a space bar in their keyboard they should jump right so first of all we should add some line of code to input check so hit the middle mouse on it and it will open it in new tab in here and we want to go to input checks so we should check the inputs okay this is the first thing to do so in here i can say key jump is equal keyboard check vk space okay so this was for input check okay so now we can collapse this and we have this key jump and we can use it so our code is again readable nothing happened okay so whenever they hit a space we have that and now we should jump but where we should do it if we should should do it in movement or apply gravity so the right thing to do because the jump is about the movement we should go to movement okay so in this movement we check for jump okay so i want to add it up here you remember these if in here it's just checking um if we are going to write or lift work right walk left run right run left and i will show you how you can implement that run that run function but for no let's add this jump in here first of all we should check if key jump is pressed that's the first thing to do but when should jump happen it should be where the when the player is on the ground so first of all we should check if we are on the ground at all so we should say and place meeting like before x of the player or the next input y of the player plus one pixel okay so we check if the player uh y position plus one pixel is at the ground so node we can jump okay and what we should check we should check obg obstacle okay why we did use up second if you didn't watch my last video let me explain it first so in our project we have tree we have rock we have ground we have wall and we wanna be able to jump on them and jump from that okay so we create this obg obstacle to detect as a ground all the way okay so we don't need to check all the objects we just check obj obseco please watch my last video about this platformer it has a playlist and whenever this happen we can change the vertical speed what what was vertical aspect was vspd and equal the vspd that we have minus a jump value in this case again let's just use 10 in here and after we've done this i want to show you trick to have all of these static values in one place and i will show you that don't worry so in input check we check for the space key and we put it on key jump and in movement function we check if the key jump is pressed and if it's pressed and we are above of any obstacles or ground or wall or tree or whatever we can change the vsp right so know that we have this let's just run it we are up here and now you can see we can jump you can see that we have we didn't have animation why we did we don't have animation right now because i want to show you the right way to do animation and i want to use a state machine so it will be the right way and the more readable way to do animation in game maker so know that we have this jump we want to change it because it's jumping too low okay but before that i want to go to create function of our obg player and add some value at top of this create function create event and what this is is i want to call it player value values equal so with this we put all the player values like jumper speed like run speed like walker speed or whatever a static value that you want to use in our game in just one place in player values okay so first thing that i want to add here is walk speed okay so i i want to name it walk speed and after this we should put a value in here i want to say let me see in here if you remember the value for hspd is 10 so let's just change this to 10 after that we want to jump a speed i want to equal it to 10 it's not equal you can see it so know that we have these player values in one place let's use them in here in input check you you see that i put some movement functionality in input check and i shouldn't do that so let's just cut this and paste it in movement function in here in top of this and let's just run it again to see if if everything is working and everything is no working and our code is more readable input checks just have the inputs movement have in movement and gravity have gravity codes okay so you remember that we create these player values and all of the values that are static and we want to use it in our project is at one place so let's just change this 10 that is for walk speed to player values dot work speed okay and for this jump a speed in here again we can say player values dot jump speed and that's it you can see it is more readable and if we run it it it should work like before everything is working like before and we can change all the value like jumper speed to 20 to see what difference it make okay so yeah a jump higher and um because we use that obg obstacle it can jump off of this lecture in here it can jump off of this ground and off of this wall as well so everything is working right how we want it in the next video i will gonna show you how you can use a state machine for your game to be more readable and be easy to understand and develop so please hit that subscribe button and if you want to help me hit that like button as well thank you very much for watching bye you
Info
Channel: navidrct
Views: 36
Rating: undefined out of 5
Keywords: beginner, beginner gamemaker, jump, jump in gamemaker, platformer, platformer in gamemaker, right way to write code in gamemaker
Id: i6UhyEvOEds
Channel Id: undefined
Length: 9min 11sec (551 seconds)
Published: Sat Dec 18 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.