Make an Action RPG in Godot 3.2

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
good morning afternoon or evening wherever and whenever you are my name is Benjamin and welcome to my action RPG Godot tutorial series I'm really excited for this series we're going to be making the base for a small action RPG game I'm going to show you right here what we're going to be making so we've got a little character that can move around on the screen we've got enemies with an artificial intelligence they can damage us we can damage them with our sword we can roll around we've got collisions set up with these walls right here and that's an Auto tile we've got collisions with these trees with this grass we've got help there's hit boxes and hurt boxes all the basics that you need for an action RPG now this is going to be the scope of the project we likely won't do a lot more than this I want to keep it pretty simple this will already probably span I would guess somewhere around 20 to 30 different videos in order to make this so it's going to take us a while but I think the payoff will be great and I think we'll have a lot of fun along the way so let's get started we're gonna open up Godot I'm using I'm using Godot version 3.2 stable now there's a new 3.2.1 stable today I might end up downloading that and starting to use that as well so once we open it up we're going to do a new project oh and before I get into this I want to say that this is going to be fairly beginner friendly but I do expect you to have some knowledge of programming but you don't have to have a lot it's going to be mainly aimed at beginners so I'll do my best to explain things as I go along but if you've never done any programming your life you might want to go look at some other basic programming videos first learn about variables and functions and stuff because I'm not going to explain all of those in great detail but other than that it's beginner friendly so we're going to create a new project we did a new project over there we need to pick a folder to put it in so I'm going to do Brow's right here and come into a folder that I want to put it in you guys can put it in any folder that you choose will do YouTube tutorial videos here and select the current folder and we'll call this like our name here action-rpg and create folder create and edit and that should open it up here now I need to actually import the resources for this and you guys should find the resources for this inside of all I'll put a link to the source the github source to this project in the description and so you can find that and then go download the zip file in there called action RPG resources so you can download that zip file unzip it and import these resources into your project as well and you can see I've just opened it up right here I'm going to select all of these folders and I'm going to drag it and drop it into this little file system down here and Godot will import those oops we're actually going to we're actually going to delete those because we actually want to make sure that it imports them properly for rights so let's do this again here let me move this out of the way we'll come up here and we'll come into our import as here on the import tab basically the problem is if you import them in by default they will be they will have a slight filter to them a blur you can see this pixel this doesn't look like pixel art right it's designed for an HD game because we've got some blurring and aliasing right here so in order to fix that we need to come to our import tab right here and we need to turn off filter and re-import you can see now we've got that this is this is a little bit blurry too but that's this is how this was created it's not actually Pixlr it's just low res but we can set our preset to 2d pixel so we'll select 2d pixel and then we'll do re-import and then we'll come to preset and do set as default for texture so once we set that as the default for our texture we can click on this and delete it yes now go into our resources and drag them all in and drop them into our file system over here again and let's make sure that that work will come into our world I'll drag in a bush and holds I'm holding scroll and or holding ctrl and scrolling in order to zoom in and there that is some nice lovely pixel art right here so there we go we'll select that and delete it and these are just this is just our artwork and sound effects for the game so we haven't imported in any code we're gonna be starting from scratch you will program everything along the way so the very first scene that we're going to make right here in Godot you need a scene a scene is kind of your level it can also sometimes be the different objects in your game they can be their own individual scenes but each scene can be run it can have a camera attached to it this first scene that we make will be a level that our character can move around in and we're going to make this a 2d scene so we'll just click on 2d right here and we'll call this world so we'll call it world and we'll hit ctrl s and we can save this scene and since this is kind of like our overall world scene that we're gonna be making here I'm just gonna save it here we could save it inside of this folder but I'm just gonna save it here and the root of our directory so now we have this scene right here and we need to set up our camera if we run this game so if we click the little play button up here to run it you can see no main scene has ever been defined so we need to select one Shore we can select the main scene will select world and then it will run our world scene here the problem with this scene is that if you grab a bush or whatever and drag it in and run the you can see that this bush is tiny and that's because it's pixel art and our game is not set up for a pixel art game yet our view here is not set up for epics our game so let's actually drag this right here up a little bit higher and we're going to come into our project settings and we're going to set up our project settings to make this game work for a pixel art game and the first thing we want to do is scroll down in general in the general tab will scroll scroll down to display right here and window and we can set our width to 320 and our height to 180 so that's a much better size for pixel art close and you can see now that this little window right here and it might be hard to see depending on the resolution of the video but this little window right here is set up for a pixel art game like this Bush looks about to be the right size so let's run the game again right oh well that's just a really tiny window so that didn't actually help right we want we want this window to be bigger but we want to be zoomed in so how do we fix that well project settings we need to set our test width and test height so this is basically the width and height of the window so not the actual view in the game but the window on our screen so we'll set this to be 1280 by 720 I think that's four times the size yeah that's four times the size so we'll be scaling everything up by four times so let's close out of our project settings run the game again and wait a minute this is kind of back where we were before right why does this why is our windows the right size but this hasn't scaled yet well we need to fix one more thing come into project settings you need to set your stretch mode right here and we need to set it to 2d and so what that will do is it will stretch our small little win our small little game view here up to our test width and height here and if we run the game again you can see now we're getting exactly what we need for this pixel art game so let's get well we can just let me just leave that bush in that's fine it'll be a happy little Bush right got Bob Ross here happy little Bush what we want to do now is create a character and we want to be able to move this character around inside of our game that seems like a pretty good spot to start for an action RPG we're gonna create a new node so when we created our first scene here we actually attached our very first node and so Godot uses a combination of scenes and nodes to organize your game and the scenes like we we can create new scenes up here with this little plus button right here are a collection of nodes organized in a tree structure so you can see that this bush right here it's got this little line coming down and it kind of indents a little bit that's because it's a child of our world node and you can actually see that our world node has a location right here at the origin 0 0 and our child this child node its location is actually relative to the world node so if we actually move this it will move the child node with it if we move the world node so we're gonna do ctrl Z to undo that but that's a very important thing to realize so if we make a node with our player that represents our player and then we attach some sort of other nodes to that root node of the player that base node and they're all children of the player node then they will follow the player as well so if you have a sword or something that's attached to your player or whatever it will move with the player its position will be relative to the player's position and that's really important to understand in our node system so that the way you organize the nodes in your tree over here is crucial for how your game is going to work so let's start by clicking on our world here and then we click this little plus button to add a new node now for this game we're going to be using the node 4 it's going to be a kinematic body now there are multiple different kinds of body nodes we have a kinematic body a rigid body static body static bodies are generally used for physical objects in your game that aren't going to be moved rigid bodies are used for objects that are going to use physics to control their behavior and then kinematic bodies are nodes that are going to have collisions but we're going to control their movement ourselves with code and that's generally better for platformer characters or in this case our action RPG character so we're going to select our kinematic body node and it should be a child of our world node you can see it's placed it in here so the bush and the kinematic body are now siblings so let's rename this here we'll name it player so our player yeah we can't see our player right and if we come over here there's no we can't actually set anything here to try and see our player so how do we see our player well let's look we can see our bush right if we click on it you can see that this is a node of type sprite so we can in order to be able to see our player we can add a sprite node to the player as a base so we're going to click on our player here and it's important to click on it because when we click Add node it will add it as a child of whatever one you have selected so now we can search sprite here and we can add a sprite now this sprite node if we move the player the sprite node will move with it right and so that that that image of our player will move with the kinematic body because it's a child of it now if we come into our click on our sprite here and we can see that it takes a texture so we can come over here into our sprite select player and player dot PNG and drag this and drop over our texture holy cow that is one giant sprite right now this is a sprite sheet and it contains all the animations for our player-character and there are a lot of them a lot of animations here a lot of frames for these animations so in order to make it so it only shows a single image we need to come into our sprite and come into the animation section right here over here on the right these are the properties of the node that we're using and so make sure you have your sprite selected we can come over here onto the right and we can set the number of H frames so currently we've got it set to 1 well it's gonna be quite a few actually so let's just set this I think it's 60 to 62 H frames we may we may end up fixing that later to make sure that we got that right but I think it's 62 H frames and now we can only see this very first frame of our player and if we update this frame property over here it actually will cycle through the frames and it looks like 62 was wrong it might be 60 yep it's actually 60 so but you can see as we cycle through our frames here it animates the character in the different motions that we're going to have we're just going to set that back to 0 for now we'll just use the very first frame for a player and we can save and if you this is something that happens quite often like let's say we want to grab our player and move our player over here into the center of the room right would grab the player and move it well actually we accidentally just grab the sprite node our player is still actually up here we just move the sprite that's not what we want so let's do ctrl Z to undo that and then we can click on our player here and there's this little icon right here that says make sure the objects children are not selectable we can click on that now if we click on the player it will actually move the player its cell and not just the sprite note of the player because we've made it so that they're no longer selectable and if we run the game again we can see our player is now inside the room with the bush we can't move around so we're going to be fixing that here soon and we'll do that by adding a script to the player so let's come to our player here and there's a little icon right here that allows us to attach a new script so we'll click this and it's going to be called player that looks good we want to make sure we put it in the right file so let's come into our player folder here and we'll open this and so that's going to save it inside of our player folder and the name of this script will be player GD and I'm going to be using GD script for this Godot has other scripting options as well visual scripting and also native script which is basically C++ and you can also use C sharp with Godot however GD script is the most developed and it has a lot of really great features it's my favorite to use so that's what we're going to be using it's based off of Python so it has a similar feel to Python it's good for beginners in my opinion so let's create this new script and Godot is going to open up our script editor right here and you can see up here at the top we have 2d which switches back to our scene or script now you'll probably have some other properties up here and like 3d and asset library and stuff I have actually chosen to hide those if you go to editor and then manage editor features you can actually hide a lot of the different features that you don't need I've set up a 2d pixel art template and so I don't need the 3d I don't need the asset library for this I've just simplified it up here if you want to do that as well as you can you can choose which editor features you want to have included so it adds some comments here this is how you make a comment with a little hashtag or a number sign and you can see that this will get rid of some of those comments you can see that this code this script extenze kinematic body to D and that just means it inherits from so everything a kinematic body 2d can do we can do inside of this script here and you always extend the note that you're attaching the script to so this note is a kinematic body 2d node so we have to extend that you can't you can't extend something different from what you're attached to the ready function right here we're gonna add our very first line of code we're gonna say print hello world the classic write classic hello world we can get rid of this pass line and save and now we can run our game so let's see what the ready function does the ready runs right when this node is ready inside of the scene so basically once it's added to our world scene and it's ready to go it will run this line of codes who are able to print hello world down in our debugger here and there's a lot of different if you if you open up the documentation here the help file you can actually if you see some code that you don't understand you can type it so underscore ready and we can see this function called when the node is ready when both the node and its children have entered the scene tree if the node has children they're ready callbacks get triggered first so the sprites ready got called before already and we can click on this over here to see what we're reading again it's usually used for initialization yeah we're going to be adding another callback function if you see a little underscore right here that means it's a callback function and we're going to be doing the physics process function okay and inside of here we'll do print hello world and we'll just delete our ready function here because we don't actually need it right now so we'll save and run the game again and you can see down working in a whole bunch of hello worlds and it's gonna start freaking out because it's printing too many actually that's a ton of hello worlds so this is the physics process and this function gets called every single tick that the physics update so if we search our help here and we paste in physics process we can see our function here and called during the physics process step of the main loop physics processing means that the frame rate is synced to the physics the Delta variable should be constant so it shouldn't change but Delta is how long the last frame took and it's only called if physics processing is enabled but it's enabled by default when we create the function here so this is a function that we're actually kind of overriding in Godot and you don't need to know a lot about that but basically this runs every single physics step so this is where we're gonna move our character okay so we're going to get some input so the important things that we're going to learn now are how to get input how to do something when somebody presses a key and we can use an if statement for this if input dot is action pressed and then we get some different options here that we can choose from and we're going to choose UI right now in GD script when you instead of doing curly brackets like this like other languages do you just use tabbing and so you use a colon here at the era yeah colon here at the end and then you hit the enter key and you can see it tabs over so we've got one tab here for this and then there's two tats here for this one we can say print you pressed the right arrow key okay so we've got this tab here so we know that this line of code right here is part of this if check the logic of this check because it's tabbed in twice here if it was like this then it wouldn't be part of that and we're gonna get an error so having your tabs is really important here and we can save and run the game now it won't do anything unless we press the right key and then it tells us you're pressing the right right arrow key it's perfect well instead of printing something let's actually move our character so we're gonna say and this this is this is a big no-no position 2x plus equals 10 okay so this is our X position and we're going to add plus equals add 10 to our x position every single frame every single physics frame that we're pressing the right key we press ok you can see we can move now the reason I said it's a big no-no is because you don't actually want to update the position manually like this on a kinematic body I'll show you how we actually move this so we'll create a variable here far we'll call this velocity we'll set this equal to vector vector 2.0 so a vector is basically just an x and a y position so our position is actually a vector as well so it's an x and a y position combined so our velocity will be some X in some Y position that represents how much the change of our position because that's what velocity is right is the change of your current position so we'll be adding this X&Y to our current position x and y every single frame and we'll do just left and right for now so we'll add if input that is action pressed UI left okay so instead of doing position plus equals 10 what we'll do is velocity dot x equals 10 or if we're moving left velocity dot what our x equals negative 10 because this is all on a grid right our coordinate system is on a grid positive is to the right negative is to the left and then gadot on a tab over once Godot has a magic little function for us called move and collide and then all we have to do is pass in our velocity so we'll say velocity like that oh and we want to do one other thing we actually want to make it so that if we're not well we'll just save it and run it like this because then we can see the problem first okay press the right key we move to the right and ten is really fast you can see we have no friction we don't stop let's set this to four instead of ten for now and here we go we can move left and right but we don't stop so how do we make it so that we stop well you could do a check that says if we're not pressing the right key and we're not pressing the left key but that would be a big pain right so what we're going to do instead is we're going to make this an else or an L if so if we're pressing the right key else if we're pressing the left key and then we can add another case called else we're not pressing either of them velocity x equals zero and we'll set our velocity to zero and now you can see we're moving back and forth our character is moving in the world we could add all the other directions as well so let's copy this we'll add the four directions will do up oops that's you I accept [Music] and down and instead of our X and want or our X's here we'll do Y and then here it will set velocity this is gonna be pretty janky oops our velocity for going down we actually have negative 4 we want that to be positive 4 ok let's press play again you can move left and right and up and down can't move any direction at the same time wait actually we seem to be able to move it at some angles and that's because the way we've set up the code I've set this up to be really simplified just using if statements however there's a trick here that is so much better so much better than this and that's what we're gonna do right now we're gonna actually delete all this code and use the better method which is creating an input vector and so what this will create is a vector based on the input that we give it so input vector equals vector 2.0 we'll set it to 0 we'll say input vector naught X is equal to input dot get action see get action strength yep that's right right so the right key - input get action strength the left key we'll say let's give ourselves a little bit more room so we can see all this on one screen input vector dot y equals input dot get action strength down minus input dot get action strength up and we can say if input vector does not equal vector 2.0 velocity equals no velocity yeah velocity equals input vector else velocity equals vector 2.0 will update this a little bit more later but let's talk about how this works okay open paint.net we've got a grid okay now imagine that you have a analog stick right you're playing a game you've got your controller there's the analog stick right now imagine that the the farthest that you can go in any direction on the analog stick is a unit of one okay it's one so now let's say that you have your analog stick and you're holding all the way to the right what do you think the coordinates would be on that analog stick well you would have an x coordinate of 1 right and a y-coordinate of 0 and let's say you're holding all the way up you would have a y coordinate of 1 and an x coordinate of 0 however in games on a screen it's actually reversed so we've actually a y coordinate of negative 1 up is actually negative on the left side you would have negative 1 and the X and 0 and the Y and down here you would have 0 in the X and positive 1 in the Y right this is our input vector this is what we're creating if they're pressing the right key but they're not pressing the left key then our action strength for right is going to be one and our extra strength for left is going to be zero so 1 minus 0 equals 1 so our X position is going to be 1 here all the way to the right now imagine you're pressing down into the left like this that would be an x-axis of 1 and a y of also 1 right and this is possible with our input so we're creating this input vector and it's going to be some coordinate on this graph like this then we can just set our velocity to be that and update our position and our character will now move in all eight directions based on the input and this movement is kind of jumpy right it's not very smooth we're going to be fixing that but that's going to be in a future video this is going to be the basics for now we're gonna save this and I'll be making another video and we'll go into making that movement more smooth so it looks a lot nicer also you may notice that we're moving faster at the diagonals and that's because if we're moving to the right the maximum speed is only 1 but if we're moving to the right and up then our speed to the right is 1 on our speed up is also 1 which actually gives us a faster diagonal speed but we'll be fixing that as well so that's gonna be it for this video I hope you guys enjoyed it and that you learn something if you have any questions let me know in the comments below I will be trying to answer questions I know I can never cover everything perfectly everyone has different gaps in their knowledge everyone you know understands things differently so if you have some doubts and questions let me know in the comments below and I will do my best to answer them this video was made possible by my wonderful Kickstarter backers this is part of my Addo course my one bit Godot course that I kick-started a little while back and part of that course was making a free action RPG series so I've been really excited to start making this I finished up the course and sent that out to the Kickstarter backers so if you're interested in that course there will be a link in this video and a link in the description and comments or you can check out the course as well I go into a deep dive in Godot covers all of the fundamentals of the engine a very broad understanding of the engine I would say yeah there's been a lot of great great support on that course through the Kickstarter so as part of the Kickstarter in this video and this video only I'm going to list off the names of all the Kickstarter backers that help support this now I'm not going to do have their full last name I'm just doing a single letter for the last name because I want to respect their privacy but yeah you'll have whatever they put as their first name and then a single letter for a middle name and last name I'll list that in this video thank you all so much for watching and I will talk to you all later [Music]
Info
Channel: HeartBeast
Views: 840,579
Rating: undefined out of 5
Keywords: Godot Engine, Godot 3.2, Godot 3, Tutorial, Series, Action RPG, RPG, Pixel Art Game, Indie Game, Game Development, Learn gamedev, Gamedev
Id: mAbG8Oi-SvQ
Channel Id: undefined
Length: 34min 7sec (2047 seconds)
Published: Thu Mar 12 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.