How to make your player move in Godot | 2D games for beginners.

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] welcome back to my channel and in today's video i'm gonna show you how to make a 2d character and how to make him move left right up or down so now let's start okay first i made an empty project for this you can make any project you want and now since we're loaded in before we even start doing anything we have to change some settings so let's go to project project settings let's go down here to display click on window for the we're going to change the width and the height for the width we're going to do 320 for the height we're going to do 180 okay now we're going to go to the test width and change that to i'm going to do it 1080. and for the test height we're going to do it 720 so we got a good screen here and for stretch we're going to go to the mode and we're going to make it 2d and for the aspect we're going to keep now let's close this since that's all done and for our main scene okay let's make a 2d scene okay you can call it whatever you want i'm just going to call it world okay click enter and i'll save that scene let's just save into the folder okay that's good and we want to make a player right so just do add new scene in do plus we're gonna for our player we're gonna make a kinematic body so you can search it kinematic body 2d right here just click on it and that's our player okay but we can't see him we want to add something to our player to see our player we're going to click on him add child node we're going to add a sprite you can search sprite there's animated sprite and there's a regular sprite for now we're just going to use the regular sprite so double click on it so to make the sprite visible you have to add a texture you see here it's empty to do that you can just go to your player and click and drag him to the folder see now he's loaded here but see if we add him here to the texture we can see that he's blurry that he's blurry but we want him to be more clear to do that just click on platformer or whatever the name of your picture is and go to import and for in presets do 2d pixel now click on re-import now is more clear okay since that's done you can see that i have many frames here because this is a spreadsheet but you might just have one frame and if you have many frames how to change that is go to sprite go to animation and h frames do how many frames you have i have eight so that's perfect right there and let's see that control us okay we're just going to save it here but it's better if we make a folder okay let's do that create folder i'm going to call it player okay and save it here okay now we have our player so now let's add him to our main scene to do that we can just go here in our player folder and drag the scene and add it wait okay drag the scene and just add it now we have our player but if we click play let's we'll select the main scene our main scene is going to be the world scene okay now we play we're gonna see that he's like up in the corner now to change that we just click on the player let's drag him in the middle so we can see him okay let's do play okay now that's much better he's just in the middle okay since everything the basic stuff is done let's make him move and to make our player move we have to code that so just go back to your kinematic body or just let's call this player will be easier okay let's call this player and now let's do add script just click on it and just do create okay now if i expand this we can see that there's all this writing we can just delete that we don't want it just click delete and now let's start coding our player movement okay before we start we're going to add some variables the first thing to do add a variable just do var okay in our variable name we're gonna call it speed and this is gonna equal to say 30 it's the speed that our player moves by we're gonna add another variable next variable is called velocity okay velocity and this is gonna equal to vector vector2.0 okay now to make our player move we're going to add a function and this function is going to be a physics process function just write physics right there physics process delta okay so if you want the player to move we're gonna do if statements say if he presses right we want to go to right if you press it presses left you want to go to left okay that's good so let's click if input import dot action action is pressed we want action is pressed one equal to ui right okay before we do anything else i want to tell you something so in the guido engine screen is split into lines like this the x-axis and y-axis so when we go to the right the x-axis axis is positive when we go to the left it's going to be negative but if we go up it's going to be negative it's not positive it's going to be negative for the y and if we go down it's going to be positive so by knowing that we can just click here and say if he presses right we're going to go to velocity dot x for the x because x is right left we're going to it's going to equal to speed okay speed now if we press start we can see if we click on the right button it doesn't work if now let's fix that let's go here let's click do move slide okay wait let's indent that let's do move slide not collide with the move slide okay we're gonna put velocity in here now let's click start again and if we press right it's not moving and let me see why is that happening if input action and not action press if input dot just action is action pro just pressed okay exactly now it's gonna work see moves if you click right and left does nothing okay so let's add left and if input okay input dot is action just pressed ui left we can just write it back it's right here do left okay and if it's left the velocity velocity dot x equals to we said that if we go to the right it's positive but if it goes to the right or left it's negative so we're going to do negative speed negative speed okay now let's play this if we click left it goes to the left if you click clay it goes to the right but there's a problem it doesn't stop to fix that let's make this knight if let me see l l is basically if this happens do this else if this happens do this we're going to add one thing which is else else is if both of these don't happen we're going to do what's in this block of code okay and else if he's not pressing not right or left we're going to make the velocity dot x equal to zero so it just stops so let's play okay but there's a problem you just move like that by small bits to fix that we did is action just press but if we do is action pressed and is action press and now we play we can see he moves if we release the button stops left right left right okay that's easy and now just let's add up and down okay if okay let's go back tab shift tab if input dot is action press is action pressed ui there's down boom ui just do down right here ui down down okay when we go down we said the y is positive so we're going to do velocity dot y equals speed okay and else if input dot is action pressed is action press ui ui up okay we're gonna make the velocity negative because if you go up it's negative velocity dot y equals negative speed and else if he's not pressing both of them we're going to make the velocity velocity dot y equals to zero now just play this and let's go left right up down okay now that's working and this is amazing so now you can see that it's very easy to make your player move and there's better ways to make a move but this is the simplest and easiest way if you're a beginner and i hope you all enjoy this video and next time we're gonna do more videos about how to make your game better for simple 2d games and if you like this video and you want more topics about the godot engine and 2d games platformer or up and down just subscribe down below and i'll see you all later
Info
Channel: All_Coder
Views: 4,329
Rating: undefined out of 5
Keywords: how to make your player move in godot 2d, 2d games in godot, how to use godot for beginners, player movement godot 2d, Godot Engine, godot tutorial 2d, godot tutorial, game development
Id: IwduUYLC6UU
Channel Id: undefined
Length: 12min 33sec (753 seconds)
Published: Wed Aug 12 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.