First Overview and moving 2D Sprite | Godot Engine Tutorial #01

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome to the second video in this video I will introduce you to the Godot game engine this be the engine we will be making our games on so first to download you got a head to this website I've got it linked in the description as well you can read about the engine here yeah then go to download and for windows choose standard version because we will not cover c-sharp support we will cover only GD script which is the coding language this engine uses you can also download it for Linux or the server but only for Linux and what matters is just a standard version 64 bit just download it press the installer and it's all really really nice really fast it's just like a 28 megabyte installer so it's very very clean so then start program out by the way there's a second download option you can download it via Steam as well and run from there it will take you to exact the same interface here here this is our project list in this we can manage and import and open projects for now we just want to go with new project for the cut I had to change the language from German to English so that you can understand it better for now we just used standard path and for a project name you can name it whatever we want I just named it YouTube tutorial then create a folder the automatically do dusters for the opengl I to go with opengl 3.0 it's just like an updated version 2.0 is really just if you want to for very low-end machines this will directly take us to the engine where this always thought so I begin with covering the different windows here for now we have the biggest window here in the middle this is our viewport we can see it's a 3d map of some kind this is where we'll be doing the visual editing in here up here you can see we've currently selected 3d so Godot engine has support for 2d and 3d games in this first series we're gonna cover just 2d so if we go to 2d you can see we now have a blank 2d plane here with all our measurements here and there and this is our screen then we have a third option script this is where we'll be doing our coding in so all the hard coded things except for shaders there's a second interface we're recording here that as a clip doesn't matter for now just leave this on 2d on the bottom left if you have it set up like this by the way you can set up the layout with this so just click the three points to to select the scene and we can just move it down here let's move that up again and we now have our scene here so for the bottom left there's our file system like any Explorer we can split this into a list and icons or we can just leave it on a list you can do it however you like then up here we got the import tab this is for resources like sprites for example this be the settings how we want to import them into the engine the scene tab is probably second most important part here we're gonna lay out our scenes what scenes are I'll explain in a moment here we gonna handle the objects layers etc then on the right we have the inspector the inspector will tell us all the properties and settings of a node that we click here in the scene port so it's like if you go to an explorer and right-click properties and the node handles things like groups and signals we'll come to that later of course so that's the main windows for now there's not anymore up here in the scene tab you can do things like and every other program create new save as open reefs and convert to with this this is going to be very important up here we have our project settings or tools and and the export button the project settings we'll come back later debug is exactly what it means it's some tools for the developers to make life easier here are some editor settings so like the program settings and here's the Help button so I think we should start by learning how exactly is game made in this engine so we have to define some kind of hierarchy the top node okay I'll explain what nodes are in the first place if you go here to the plus you can see his create new node here's a list of very of many here's a list of many different objects like an audio stream player a parallax background a time world environment I go into any of these later for now just choose a blank note that's the top not that everything inherits from so now we can see that our scene has a node up here and we can see in the inspector we already have some properties pause and script these don't matter for now and we have some signals and groups as well so what is a node you can think of a node as an object so for example this is our main node that the scene contains a scene is another version of an object you can create an object out of many nodes but you can use this as a node as well so for example if you just want to have an image laid down on the plane we can delete this and we can create new node and we choose right so sprite is a 2d image there's not more to it we can see there's not anything happening does this weird cross but nothing more that's because we haven't told the sprite what picture to use over here in the inspector we see the different properties of the sprite note by the way double click here to rename we can see this has texture property and currently see says empty so if you if you have loaded a new version of GD project you should have this icon dot PNG you can use any PNG down here and we just drag it to the sprite and we should see it appear up here so we can already see that in not really in the middle or anything that's not really important then I'll explain how the coordinate system works in game engines so mostly from school or things like that you know that coordinate system starts in the bottom left corner with the 0 0 the y-value increments or gets increments as we get up and the x-coordinate increments as we get left in game engines it's a bit flipped so as you can see this bright we created is at position 0 0 how do we know that well first note we create are always at first at 0 0 and down here in the inspector we have this node 2d section no 2d is what all 2d objects have these are the properties and here's a transform we can click on that and then we have things like rotation degrees scale and position we can see the x value and the y value are both set to zero if we increment the x value let's say by 300 it moves to the right so the x value as we had before increments as we get far to the right so what about the Y value no let's put it through 300 also and it gets down so the Y value increments as we get down that's one really important thing to know so now we have this sprite here in the scene we can see unsaved so this is the note but this up here is the scene it's like a collection of notes we can save this as sprite or t sen t sen is just a seam so we now have it as a file down here and if we double click it it opens right back to this so using this in another scene is also possible for example let's create a word or like an environment we can use it for now let's take a 2d scene cuz we're making a 2-d game and it automatically produced know to denote let's name this word now what we can do is click this link button up here this is to add a scene we saved as a note you can always also do it like this so now we have our sprite node in our world so a no 2d is like a container so but that's pretty lame right so if you see these buttons up here the first one is to play the game so run it for testing it out this button here is to play only the scene you've selected so in our case it would be this scene we had haven't saved yet and this button is to play any see that we select so let's try and run just this see then we get notice the scene has never been saved of course we want to save it and we just save it as world dot es en now we wait and we have our game it's not doing anything but we have our game it starts and we see the sprite everything's fine but that's pretty lame right so actually let's delete this and make ourselves a player so I don't save this so for a new player we first create a new scene so that we can later just put the scene in the word and it works so click on this + up here and we have a new 2d scene here but we don't want to use any of the options here we want to use a node called kinematic body 2d this is just what you most commonly use for characters or enemies in games it's a movable object that you can do collision with and it's just the most suitable so we now have our kinematic body 2d let's rename this as player but we get this weird icon here that says note configuration warning this node has no shape so it can't collide collide or interact with other objects consider adding a collision shape to D or collision polygon to D as a child to the final shape this might sound a bit confusing but it just says this object is supposed to be colliding with something but it doesn't know where to collide it it doesn't know how big it is it doesn't know anything so first so that we can see the player let's do the exact same thing as before let's add a sprite so we just type in sprite up here you can also use this node system but just type it it's a lot faster yeah we can leave it sprite and like before we gonna attach a picture to the sprite and there you have it but that hasn't fixed this error yet so I'm gonna introduce you to another type of node and it's called a collision shape collision shape 2d in our case because we're making a 2-d game we get another warning the shape must be provided for collision shape 2d to function please create a shape resource for it so it tells us you know know that you collide with something but you still don't know how big is your hitbox or you're colliding box so how do we fix this we go back to the inspector on the right and we have a shape property which is currently empty let's create a new shape so our oz bright is pretty rectangular so just choose your rectangle shape 2d and then click on it not the arrow but it and now we get the extents what are the extents the extents is how far does the shape go from the middle point so if we have 10 the shapes with will be 20 so but we don't really know how big to make it right we could use these to line it up properly but I'll show you another thing you can double click on the icon and here in the inspector you have how big it is it's 96 by 96 so we would have to set our extents to half that so let's go back to our collision shape and yet we've done a pretty good job it's at 48 and now we get no error whatsoever and we're pretty much done with our collision setup for the player but it doesn't do anything it just stands there and collides but there is nothing to collide with and yeah we're working on that so you for shortcuts you can always just press ctrl s to save the queen' scene and we'll just save it as player TCN so for now we're gonna set this player to be working in the world so just go back to our words in and drag the player on to the world and now we can see in our world we have that player and that player is these three nodes so the next thing we want to do is how do we move this player so ideally you want to move it with your keyboard for this we're gonna write our first program we're gonna use this button up here which says attach a new or existing script for the selected note we're going to select a player since it's the player we want to move and this opens this frame inherits language GT script perfect we leave it on that kinematic body 2d that's the type of node it is so yeah that's right template you can you can change whatever we want and we delete like everything so just choose empty and the path also is right so click on create and this opens a text box for us to work with to make it a little less distracting you could use this button up here to make the other windows disappear and just have decoding I leave it on that just for simplicity so to anyone who hasn't ever done any programming there is going to be a really in-depth series about coding principles in general with examples but I just want you guys to be finished in this video and say you have moved your character so if you don't understand everything in this video it's totally fine I'll explain the concepts in there in another video and tutorial I just want you to have something on at the end of this video so what do we want to do if we press the right arrow on the keyboard it should move right so how do we do this first we go to project up here and go to the project settings this window is now very filled with information we don't need us at all we just use input map there is where you can use any key to act as an input our arrow keys have already been implemented so we have you I left for the left key you I write for the right key you I up or up key and you I down for the down key so this is perfect we just leave it on that back in our player script so this is gonna be the program that controls our player we just and we first have to define how are we gonna check if an input is pressed and that's the first program in principle in this you have to understand there are functions a function looks like this your first right func for defining it as something to do and then you can give it a name for example step that doesn't do anything we have to do this open paren thesis which leads us to the second thing some of the functions have input parameters these are what is going to be in those brackets for example in the function step to make it on something in the real world we could use a length for that step so we would write lengths so that we have a function that lets us do a step and we can choose how wide that step needs to be just close the bracket if you are done and then to tell the function which part of the code belongs to it we write this double points and then we press ENTER we are automatically getting a tab here so that's perfect so now everything we write in this segment will be called when our function step is on so we cut to something like move length but that's not how it works in our game we have to check on each frame of the game if an input is pressed and that's perfect because we already have some functions in GT script that are called on specific events for example there is the ready function the ready function executes every time the node is instanced so at the beginning of the node then we have the process function which is called every frame so in this engine every six years of a second because this engine runs each game 60fps so it's perfect right we want to check on every frame if a key is pressed so we already have function that's that saying I do this on every frame so we want to check if a button is pressed like just in the English language that calls for an if statement an if statement lets us say something like if this is true then do this we want to test for now if the right arrow is pressed then move the player and we do this by writing input input is everything that we defined up here so there are different modes for keyboard keys to be in write different states there's a pressed there's released but we really want if it's pressed in this frame so we want dot is and then we get a drop-down menu with every check that we can do just pressed is when you press the key it executes once no matter how long you hold the key release does the same for releasing key and the differences is action pressed so this just says if on this frame this key is down I do this and that's perfect because we don't want our player to stop moving after doing one step right if we hold down the button longer you should move longer so we use is action pressed just enter that with Enter you can move about this drop-down menu with the down and arrow keys and now we have a list of all the here defined input options that we want so we want you I left because it's the left arrow key so we type UI left and we can also correct it so it now checks if this button is pressed so how do we tell it to move we used double points again like in the function so that every piece of code that's incremented like this it's going to be put in this if statement so if I write something here it's called in the if statement here not so how do we tell our player to move it's very sleep fairly simple that's the reason we choose kinematic body 2d for the people who did is have in school everything with kinematic means motion and force so we have a function for moving and that's called move and slide so there's different moves but we're gonna move in slab using move and slide because it's the easiest one so now it knows if the button is pressed I should move but it doesn't know where and it doesn't know how far for this we're gonna be we're gonna be using a vector so everybody who had physics vector math or something like that it's familiar with that but everybody else I'll explain to you a vector to in our case we'll be using a vector to since we're making a 2-d game if we want to make a 3d game we have to do it with a vector three vectors to contains two informations an X and the y coordinate those are respective to the current position and with that you can check in directions that are respective to the object for now let's say we want to move the player if we press left 10 pixels every frame to the left so first we'll have to define a vector - like we talked about and it tells us here it wants a float X and a float Y so what is a float a float is a number with decimal points so for example one that 0 0 0 0 1 would be a float one would be an integer if you need anything of these basic programming things just look in the programming series I will have later so we previously defined what our coordinate system looks like and we want to move to the left so we want to modify the x coordinate so we can already to type in 0 on the y axis because we don't want to move up and down and we previously said if we increment X it moves to the right but we want to move to the left so we'll have to add a negative to it this will move it by 10 pixels to the left each frame this action is pressed that's perfect we just have to identify four other things so just copy this and paste it we have to do the same thing for every key so you I write positive 10 so you I up here it gets a little bit trickier we now have to modify the y-axis and we previously said if we increment Y it moves down so if we press up we also want to negate from it and then just do the same thing for down [Music] and now we should have perfectly working play we can test this by running our world scene with this button you can also press f6 if you have a keyboard that has these keys and now ok wait 10 pixels it's like a little bit too less let's do it by a hundred pixels and now we can see that all our player moves as we press the keys and it automatically moves diagonal if we play if we do it with two keys or it moves by nothing if we have two keys that negate each other this is because if we press up and down at the same time we move by minus 100 on the y-axis but also by 100 so if we add this up add these together we get 0 so we don't move at all another example if we press UI right and up you notice that we go in a diagonal line right up because these two added will be 100 on the y-axis sentence 0 plus 100 and minus 100 on the y-axis so you're gonna move minus 100 on the y-axis at the same time 100 plus at the x-axis so it most diagonal to the top right so I hope this gave you a brief overview of how we can be doing this I'll have to other serious like I mentioned the in-depth programming where I'll explain concepts of the video game itself in depth and a programming tutorial series where we cover everything that has to do with the scripting itself how to get properties how to set everything just for everyone who hasn't coded yet or hasn't used the GD script language at all so I hope you enjoyed it and please let me know if I told anything wrong and a quick note I I'm here to improve my English as well so if I said anything wrong feel free to correct me in the comments I'm German as I mentioned so my English isn't that good but I hope it's okay and yeah then let's see each other again on the next video [Music] you [Music] you
Info
Channel: ifClause:
Views: 243
Rating: undefined out of 5
Keywords: Gaming, Coding, Programming, 2D, Godot#, Godot, Engine, Gameengine
Id: w82gxKfgqIY
Channel Id: undefined
Length: 36min 21sec (2181 seconds)
Published: Wed Nov 20 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.