Crash Course ~ How to Make a Resource Gathering Game in Godot 4!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everybody Chris here and I wanted to go over everything we're going to be discussing in this resource Gathering RPG course for the Godot engine so we have our character with a tool equipped we can change our tools out Simply by clicking on the Hotbar icons below so being able to switch between a ax a hammer and a pickaxe and we can use these tools to harvest the nodes which are relevant so a pickaxe of course being able to swing at a rock node and you can see that when we Harvest it the pickup rocks will come out we can gather those as resources those get added to the inventory represented in the top left If We Gather other types of resources those will be represented up there as well so to harvest a tree resource we need a normal ax note we're walking across a animated Bridge here so we're setting a lot of this up with tile maps and tile sets some of these objects are just dragged into the scene with Collision shapes and some scripts added to them like the trees so these trees are different from the other ones because they give us a different type of resource so you can Harvest five of those pick them all up once again being added to the inventory we're able to walk across these Bridges and go to different terrains and then down here of course we can Harvest more trees another thing I want to point out about how we've set up the animations is that when we swap out a tool we can use the same animation if it's relevant so we switch to a different tool and they can reuse the same animations because what we're changing is the position rotation and scale on the Node rather than changing the animation on the tool itself so that also saves in needing to animate some of the frames there so that's basically the gist of what we're setting up in this project tile Maps tile sets walkable player with animations a Hotbar and a resource item display complete with a basic inventory and a camera that follows the player in this world setup mostly with tile maps and tile sets in the Godot 4 engine so we'll go through every detail of setting up the scripts creating our nodes designing our game level in this series if you want to pick up the final scripts or the final project complete with the game art you can find the links in the description below or if you prefer you can just follow along from scratch because we'll be covering all of the code in the videos and you can just follow along there hello everybody Chris here and in this video I'm going to be showing all of you how to create a resource Gathering RPG inside of the Godot engine so if you've been following my channel you know I did a similar video with unity engine as well so we're going to be recreating more or less the same project now in the Godot engine for those who prefer to use Godot and stuff so for this tutorial I'm going to be using my own art pack gatherers exterior RPG pack it's not required to follow along but it does have resource nodes items you can pick up tools you can use in order to harvest resource nodes and a character with a swing and walk animation that'll make it easier to finish this tutorial so if you'd like to pick that up you can find the links to it in the description I'll also have the finished project at the end of this tutorial for download as well once again though it's not required you can basically use whatever our assets you want for the project so if you are going to be using the art Pack download the our only dot zip version since we're not using the unity engine we only need the assets to bring those into cadell so inside the zip we have the art folder so what I'm going to do is bring this into the file system for our Godot project so to get to the root folder of the godo file system find resources colon slash right click on that and do open in file manager so this brings us basically to where we have the project set up and we can create other folders we'd want and here so I'm going to right click and create a new folder and I'm going to call this alright let's double click into it and now from whatever zip management tool you're using whether that's 7-Zip or winvar just drag the art folder into the project so this is now an art folder listed within art I'm going to rename this to be gatherer's exterior so that we know what art pack we have set up inside of the art folder if you double click into it then you'll see all the other folders and the other assets that you can use for your project so now if we click black into Godot Godot should automatically recognize all the files we brought in and then we'll be good to go so the first thing I want to show is how you can equip a tool to a character and switch between tools while maintaining the same animations and use them to harvest the different nodes in your game so let's start our project off by creating the base for our character so instead of clicking 2D scene I'm actually going to click other node here and let's search for character so we're going to find character body 2D which as you can see here is a 2d body node for characters moved by Script sounds like exactly what we want so let's click create next we can take the name of the node character body 2D and rename that to be player so that we know that this is the player character for our game now before we go further let's actually save this scene inside of our project so that we can reuse it anywhere we need and we don't lose our work so I'm going to hit Ctrl s to save our player scene this is the root of our project so let's create a new folder and I will call this new folder characters to store all of the characters whether that's an enemy or a player character instead of 5K click OK and let's say if player.tscn inside of here so now in the file system if you open up the characters folder you should be able to see our player.tscn scene and anytime you want to edit it you can just double click on it and open it up so our player same obviously is going to need more than just this character body 2D which handles the physics we want to actually be able to show a Sprite inside of our character as well so let's right click on the player node do Agile node and let's look for sprite 2D so this Sprite 2D node will be the base body of our characters so I'm actually just going to rename with F2 and I'm going to call this Sprite 2 denote body to be more specific on what it actually is so now if we open up our gatherers exterior characters we should be able to find the animations for our characters separated into their own individual Sprite sheets so let's start by taking gathererswingdown.png and I'm going to drag this into texture so as you can see this has three frames of animation and they look quite blurry right now so to fix the blurriness for the rest of the game let's go to project project settings go down to rendering textures and where we have default texture filter change that to nearest and hit close so now the pixel art should render correctly in our game next we want to take these frames and turn them into an animation so let's right click on player and add another child note and we're going to look for animation player so let's create that and this will open up the animation window at the bottom so click on the animation button go to new animation and let's name the first animation we'll say swing down and click ok so first we need to slice up the Sprite sheet so I'm going to click on the body node let's go to animation and for H frames I'm going to set that to 3 because there's three frames here so three frames going horizontally one two three means we change H frames to three so now the spreadsheet has been set into three separate chunks and I want to make sure that when this animation starts that this H frames value is keyframed at the start so that it will automatically be set in this Sprite node so click on the keyframe button and you'll see this as long as you have the animation window up down here so click on keyframe and then click create for new tracks and if we look down in our animation window you should see the keyframe with h-frame set to three here so that means when our animation gets to this point H frames is going to be set to 3 on our body Sprite 2D node okay next let's click on body again and let's add in the frames so we're going to start with frame Zero from our spreadsheet and then add one and two in before we do that we want to change the snap on our animation to 0.2 since these animations were set up to be 5 frames per second so 0.2 seconds means you get 5 frames in one second now that that snapping's done if we click on the keyframe add button for animation frame we'll get the confirmation to add a new property and add the key so hit create and immediately after that frame will jump to one and you'll see that the snapping of our animation moved to 0.2 seconds so every 0.2 seconds it's going to snap and we can set new keyframes so to automatically add the second one in frame is already set to one so we want to keyframe that so just click on ADD keyframe and then we'll have frame two and we click on this again for our 0.4 seconds part of the animation so now we have these three frames we're going to change the timing of our animation to be 0.6 seconds so over here on the right type in 0.6 and we don't need looping for this animation so you don't need to toggle this on or anything but if we hit play we should be able to see our swing down animation the last thing we need to make sure is that when this animation is playing that the right texture is set inside of our animation as well so go to zero seconds of our animation and click on the keyframe button next to texture which will add the texture property to our keyframe track so let's click create there and this now means that it will switch to putting this as the active texture in our body so that we're actually showing the right animation hframes slices it up to the right number of frames and then these are the frames that we're actually playing and those should be the three things we have to have for our body Sprite 2D the next thing I want to do for this animation is to make it so that we have a tool in the character's hand so we're going to need to add extra nodes to our player and it will actually make this a separate saved scene inside of our project so we could actually add it to other characters as well but let's start by right clicking on player I'm going to add a child node let's look for node 2D and I'm going to rename this to be let's say hand equipped as in the item that we have currently equipped to our character's hand now under the hand equip I'm going to right click add a child node and let's get a Sprite 2D and then let's also right click on hand equip add a child node and I'll look for a area 2D node so this is a node for detection so we could use this as let's say a hitbox so when our character swings a pickaxe or a hammer or something it can damage a resource node or we could do basically the same thing with a sword if we were trying to attack an enemy later on so let's create this area 2D under the hand equip and our area 2D is going to need some kind of collision shape so that it knows where to detect other objects so I'm going to right click inside of this add a child node and then let's look for a collision shape 2D in inspector for shape I'm going to change the shape to let's just say a rectangle shape for right now and for the Sprite 2D node let's actually show a tool so in together's exterior pack I'll open up tools and let's just drag ax copper PNG into the texture there to make sure that the X actually renders on top of the area 2D I'll just drag the area to D above the Sprite 2D so that's just the default rendering order there whatever's in bottom is going to show on top and this makes it a little bit easier to actually see our ax now let's also shrink the area 2D size so I'm going to go into the area 2D Collision shape and let's shrink this to basically match the size and shape of the ax head so something like right around there should be pretty good for our ax detection area okay so now let's add in animation keyframe values for the tool itself inside of our swing down animation so we can actually animate multiple Sprites at the same time in one animation so for equip Sprite what I'm going to do here is rather than enabling flip H for the offset which you can see flips the Sprite but it doesn't actually change the positions of child nodes like the area 2D which causes us a bit of a position issue so what I'll do instead is I'll take the equip Sprite we'll go to node 2D in the inspector turn off the link between scale X and Y and take the scale X and set that to negative one which is going to flip it from right to left so we're going to want to keyframe that value uh inside of our animations so click on the keyframe button to add the scale property to our track and now our animation will have the ax facing the left but also it changes the position of the area 2D which helps us out next let's position our equip Sprite over here to the hand of the character and I'll add a track for the position as well and let's lastly do rotation so create the keyframe for rotation now that we have these properties in if we want to automatically have this update whenever we set it to a new value add a different keyframe or in this existing one we can click on this Rec record button at the top of our 2D window so Auto insert Keys when objects are translated rotated or scaled toggle that on now let's go to 0.2 seconds and we can change the values of our scale rotation and position and it will automatically keyframe in the animation Force so if I just drag the position of our ax up to here you'll see that the position keyframe is added I'll hit e to go to rotate mode and now we can rotate this Sprite down like this hold Ctrl down if you want it to snap to 15 degree increments and let's get it to be something like there negative 180 degrees I'll hit W to go to move mode and let's position it into the character's hand once again okay so let's go to 0.4 seconds now and make sure you're clicking on the equip Sprite still and with record mode enabled let's go to E for rotate mode and rotate our Sprite downwards I can hold Ctrl to snap it to different increments if I want that to be a little more precise and then let's say w to go to move mode and move the position of our X down here so that it ends up roughly right in front of where our character is standing maybe we even want to go a little further than that and I can e to go to rotate mode Let's rotate it a little bit over here and just kind of you know just keep changing the position okay and something like that looks good this should be a good hitbox for in front of the character so we can go with that for right now okay now we want to test our animation so go to zero seconds in our animation and hit play and what you'll see happen is that our X does animate into the correct positions but in between those keyframes the position automatically adjusts to a in-between value which gives us a little bit of a wonky looking animation what we actually want to occur is that the animation values only change when our keyframes change so that we can sync up the positions with the actual Sprite animations of our character so on the right side of our animation track you can come down here to where you see these little lines next to scale position and rotation and you want to change the update mode from continuous to discrete if it's in discrete mode then the values only change when the keyframes change so if you do that for all three of them and you hit play then now the animations are only going to change three times at those exact intervals and now the animations sync up with our pixel art character much more nicely so because we set up our equip Sprite to only change the scale position and rotation through our animation we can now change something out like the tool to a different tool like let's drop the hammer in here hit play and we play the same animation with a different tool we could try adding in the pickaxe here and more or less without changing much else it's going to function about the same one thing we could do is just make the Collision shape a little bit bigger so I'll just try to adjust it like that and now if we change the Sprite on the Equip to the Hammer then that will work if we change it to the ax that works too and the pickaxe should be a good enough hitbox there as well so with a little bit of tweaking we can get one animation to work for different types of tools and now what we would need to do is just have a script set up so that we can change our tool to a different texture later on and have different tools interact with different objects in the game for instance a ax is probably going to harvest trees but a pickaxe would Harvest or or Stone from a rock let's make another animation for right now I'm going to click on animation new and let's do idle down okay so for idle down here we want to go to the body and we're going to change the animation set in the texture here so let's go to characters and let's look for the walk down animation so for our idle we're just going to use the first frame of walk down so let's drag that in there we're going to set the texture keyframe that in our idle animation track so let's create that texture for age frames there's four frames here so 4 for H frames keyframe that hit create and then keyframe frame 0 in our animation for this animation we can just take the duration to let's say 0.2 seconds I'll take snapping and make that 0.2 seconds just for consistency we can hit play and that is going to be our animation what basically the character just stands there so now we should also keyframe the position of our equip Sprite so that when our character is hiding down the Sprite is still in the correct position so let's hit W to move our Sprite and position it into where our hand should hold the Sprite so I'm going to keyframe position here that's keyframe rotation as well and scale as well so just to be consistent between all of our animations we'll just keyframe position rotation and scale to something for each of our animations so when we come into this animation idle down the pickaxe or whichever tool we have equipped is going to position itself over here and we go back to swing down and hit play and you can can see that they have different values for each of those animations next we can also do walk down as an animation so let's go to new animation lockdown so for walk down we're going to use the same texture file in the player body so keyframe texture up here create that keyframe the H frames as well and then let's add in all four frames to the animation keyframe and then hit that three more times but before that let's change the snap to 0.2 okay and then actually set the value to 0.2 here okay and then uh frame one and the inspector window keyframe and then frame two we have that keyframe and then keyframe and then that's our four frames of Animation so take the duration and change that to 0.8 and toggle looping on and now we can hit play and uh there's our walking animation so of course we're going to need to position the pickaxe tool in the correct spot depending on where the hand is positioned so let's go to equip Sprite and then let's keyframe position hit create or space bar rotation enter spacebar and then scale space bar as well so we have those properties in there oh and make sure to change them to discrete mode for all the animations should be discrete and idle down as well though I don't think that made a difference there but just for consistency always make it discrete okay okay and now we can do the rest of our frames of animation for the equip Sprite and walk down so go to snap 0 0.2 seconds in and let's position the tool W for move mode Let's get it right around there 0.4 seconds okay back down 0.6 seconds and it should be forward okay so now if we loop our walk animation it's going to be roughly like that so we can kind of decide if we want to have some rotation added in here as well as our character kind of Bops up and down I think right now though it's okay to just have it um just moving a couple pixels with our hand there I don't think that's too bad so let's actually just Ctrl s save our scene and we have three animations set up later of course we'll do the different directions for left up and to the right okay now um if we look at our player node it's had this warning for a while about having no Collision shape so a character body 2D is a physics object and for it to actually work properly it needs to have a collision shape to go along with that so let's right click on player ADD child node Collision shape 2D and then let's actually just add this end so a new shape in the inspector you could use a rectangle shape or a capsule shape I think both will work okay I will go with capsule um since our character is kind of rounded anyway and then let's take the size of the capsule shape and shrink it down so that it's really just kind of fitting the body excluding the head I'll use W to go to move mode and let's move this down here to the bottom I'll shrink it a little bit more than that even something like that looks good pretty good where we have it centered down the middle it doesn't take up the full size of the head because really the head shouldn't be colliding with anything if we're thinking of things from a top-down game perspective so that should be okay for a collision shape we can always shrink it a little bit more later if we need to so let's hit Ctrl s on our scene and save it okay so for motion mode on our character I want to change that to floating because we're doing a top down style so our character is not going to be affected by gravity which is going to be kind of floating around the scene if we run into a wall yes the wall will stop us but aside from that we're just kind of walking left right up down with no gravity or really physics acting on our character so next let's add a new script to our player so just click on the new script button you'll see the template is checked here basic 2D movement um so we'll start with that and then we'll edit it so we have our player.gd script being saved in the characters folder let's create that so the default script is set up to be more of a platformer controller so the first thing I'm going to do is remove the ability to jump and remove Gravity from here so I'm going to cut that out and down here add the gravity let's remove that as well for the jump let's cut that out as well so we have far Direction input.get access and we can either move or we can not move and then we're going to do move and slide to actually process the movement of our character based on whatever the velocity is set on the character body 2D for this constant speed value let's change that to an export variable so that we can customize the speed value in the inspector if we want so I'm going to replace constant with at export VAR gonna make speed the lowercase and this would be a type of flow and we can leave it set to the 300 pixels per second still if we want that's fine and then we just need to update this bead variable down here make sure that the name is referenced the same so replace the capital speed with lowercase speed for both of those okay and now let's go to 2D view then let's hit run current scene up here in the top right hand corner we should be able to see our character let's use left and right on the keyboard and you can see our character does in fact move uh wasd doesn't work right now because the default keys are set up to up down left right but at least we can move left and right so we want to add in at a bare minimum the ability to move up and down as well so now to change how our character is going to move let's take the advice here where they say you should set up some custom actions for your character's movement so let's go up to the project menu and go to Project settings and go to input map so you can check show built-in actions here to see stuff like the UI accept and UI cancel and left to right up down but let's actually toggle that off and just add in some new custom actions here so the first action we're going to want to add is going to be left so type left and enter that right enter up enter down enter so these actions are going to correspond with the wasd keys or really you could choose to use whatever Keys you want but I'm going to hit Plus on left and then I'm going to type the a key on my keyboard and it will select a from the list of options so hit OK and now a is assigned to the left action so let's do the same thing for Right add event D for right okay click on up W for up okay down ask for down okay so now we've set up our movement actions let's click on close now let's come down here to in the script where we have Direction equals input git access so we don't want to get one axis now we actually want to get a vector which is going to have an X and divide axis so this will be our x-axis except replace UI left with just left and right with right but then we also need to add in up and down so let's do if our Direction so let's add a new line here of our Direction equals input dot get vector and then we need to pass in four directions so we start with horizontal negative which is left okay and then we do right for horizontal positive then we do up for vertical negative and then we do down for vertical positive okay so let's remove the first line okay and now we have this as a vector two if we want we can specify with a colon Vector two here that this is supposed to be a vector two but that's not required it should be pretty obvious so when we would be assigning velocity X that would be taking a float not a factor so what we actually want to set for the velocity is going to be velocity equals Direction times speed and then down here we can just set the velocity to zero if the character is not moving so velocity equals Vector 2.0 okay that should be just fine now the last thing I want to do is strip out any magnitude from this Vector that might show up and normalize it to basically have a total value of one so when we have the vector we can type dot normalized so we can do dot normalized on a vector to make it have a magnitude of one okay and we can get rid of these comments up here well actually I'll replace it with move in for directions and if this works that should probably be all we need to do for getting our character to move around up down left right so let's go out to our scene and then let's hit the Run current scene button and use wasd to move our character around the scene so as you can see we can move just fine now but obviously our character scale is really small being Pixar and all so let's change our window settings let's go up to project project settings and go to the general tab window and I'm going to take the scale here on stretch and change that to four now we click close run the scene again and as you can see the character is much bigger on the screen now and that should be a bit more appropriate to what we're looking for okay so now that we have a moving character it's probably about time that we set up a basic scene for our character to run around in so let's go up to scene new scene 2D scene and then I'll rename this node to be something like game level let's hit Ctrl s go up one scene create a folder for levels so I'll type in level and let's save game level.tscn inside of there okay next we need our character to actually be in the scene so in our project let's drag player.tscn inside of the scene just put it anywhere you want it to be and there we have a working player inside of our scene we'd probably want something in the scene aside from our player so let's go to Art gatherers exterior then I'm going to look for something like let's say objects and I'll go to grass and here we have some rock objects we can add to our scene so I'll try Rock tall one and let's just drag it into our scene here so now we have a rock object inside of our scene let's hit play and you can see that no main scene has ever been defined but now we can select the currency in the game level as our default level to load when the game starts so select current and now whenever we hit that play button this scene will load so we can move around in the scene and you can see that this Sprite for the rock is there but uh we're not really able to interact with it because right now it's just a Sprite so let's click close next let's add a follow camera to the scene so whenever our player moves around and the camera will go ahead and track the player so I'm going to right click on game level ADD child node camera 2D and to make this camera follow the player we need to right click on the player add a child node look for transform and we're going to do remote transform 2D so create that and this remote transform 2D we can assign that to a camera with the remote path in the inspector so assign camera 2D and now this camera 2D is going to follow our player round wherever he is on the scene so if we hit play then as our player moves the camera just stays on top of the player so it can kind of work like that now we might not want it to always 100 track the player no matter where the player moves we can have a drag setting so the player has to walk away from the center of the screen before the camera starts moving so let's hit close and let's try working on that a bit I'll go to drag let's do enable horizontal and vertical and the left top right and bottom margins of 0.2 we can just leave that as the default so let's hit play again and let's see what it looks like with the drag so now you can see that there's like a dead zone in the center of the screen where the camera won't move until the player kind of gets away from that so that might look a little bit better than always having the camera move no matter what another thing I've noticed is that the character's default speed is way too fast for the game so let's open the script and change the value from 300 to something like 200 and save that now you don't necessarily always have to edit it in the script you can change the value in the inspector since this was set up as an export variable it's set up here and you can customize it so also in the scene our Rock has no physics body for it so let's actually add a physics body to the game level so I'll right click on game level ADD child scene and let's look for a static body 2D so static body 2D is a physics object which doesn't move unless you change it by Script and it's good for floors and walls but I think it will also work pretty well for something like a rock which is never supposed to move in the scene so let's create that and I'm going to drag the Sprite under it so for the static body 2D I'll hit F2 and rename it to be resource node and let's say Rock tall and we'll come back to adding a custom script to that later so that we can actually Harvest resources from it for the Sprite under it I guess we can just rename it to be Sprite 2D as the default since the parent name kind of takes care of the fact it's a tall Rock already and now to get rid of the warning let's add a collision shape to the Rock so right click add a child node let's look for Collision shape 2D under shape in the inspector choose let's say capsule shape okay and we can see that it shows up up here in the top left so let's click on Sprite 2D and actually reset the position to zero zero okay so now all three of them are stacked on top of each other I'll take Collision shape and move that on top in the order so that the Sprite shows on top of it and let's take the Collision shape and have it match our Sprite a little better by shrinking in the sides kind of like that and maybe I even offset the position by a couple pixels so you can hit W to go to move mode and then we can drag the Collision shape down okay so next hour has no physics body associated with it so let's add a physics body in our game level and attach the Sprite to it so I'm going to right click on game level ADD child node and we're going to look for body so we can use static body 2D because it's not supposed to move so use static body 2D create and then I'll rename the static body to be resource node Rock tall I'll bring the Sprite Rock tall one under it and then let's right click inside of resource node Rock tall and add in a collision shape a collision shape 2D which I will make a capsule shape now you can see here the position here for the Collision shape is resetting to zero zero which is very far from where the rock tall is so let's actually take Rock tall one go to the transform and reset the position so now all three of them are stacked on top of each other because this list of nodes is getting a little more complicated we should really save it as a separate scene so I'll right click on resource node Rock tall and let's Save branch as seen let's create a folder here I'll call it objects and inside of here I'll create another folder called resources and click OK so let's save resource node Rock tall into objects resources and hit save okay now let's jump into the scene so that when we're editing it we're editing the scene saved to our project so click on the jump into scene button and in here we want to take the Collision shape and just make it actually make sense for our Tarbox so it should be kind of a circle right around here so let's shrink this down until we get something like that I'll hit W to go into move mode and let's move the Collision shape down to right around here connect Q to go back to select mode if we need to stretch it just a little bit wider maybe W and move it up here a little bit the advantage of the capsule shape is that you can make it more of a generic oval like an egg if you need it to rather than just being a regular Circle but in this case a circle collider would have worked just fine too so now we have the static body for physics and interactions we have the Collision shape to determine where those collisions should happen and we have the Sprite which shows the graphics on the screen for this Sprite node let's actually rename that to be Sprite 2D keeping it more generic here since the resource node Rock talk kind of already says everything we need to know about this note so let's save this node go back to the game level and move our resource Rock tall somewhere into the scene we can also hit Ctrl D to duplicate it and move the second copy up to here and maybe just duplicate and create a third one and let's bring that down there now let's hit play and test out I've seen again so we want to make sure that the collisions actually happen so let's move into the box and you can see that now we can't move through the Rocks we do have a visual sorting issue which we'll take care of in a second here basically the head should never show below the rock like this but the collisions are happening which is good okay so to fix our y sorting go to the game level and under canvas item we want to do sorting and why sort enabled so this will take anything under it any other 2D notes and make them sort visually as long as they are parented to the game level so let's hit play and test out that y sorting again so here we're behind the box so we show behind it but if we go to the front of dock now you can see that the Y sorting is working correctly so really easy to get that part working and it works pretty well next let's jump back into the player and let's finish setting up the animations and then we'll add an animation tree so that we can switch between idle and run animations and also switch to the swing animation when we need to so for animations let's go to idle down and I'm going to just duplicate this so we'll do idle up and then for that we take the texture go to Art gathers exterior characters find walk up bring that in here for the texture value and that should basically be it actually so if we bring the cursor back to frame 0 we'll see that the animation updates here if we hit play our character is just not moving basically what we want but but then the tool we actually want to show in the right hand so we are going to need to have to move it over here to the right so let's toggle recording click on the equip Sprite take the scale value turn off link between X and Y and then take the scale X and make that one okay and that should automatically update here for this scale here if it didn't then just change the value manually so uncheck the link and do one one for the value for the equip Sprite okay now we need to move it over here to the right so w for move mode and reposition it okay and you can always test by hitting play just making sure that it's going to be positioned to the right spot and then in order to get the tool to show behind the character in this case you might want to add an Z index and keyframe that to let's say negative one as the value so you see if we make it negative one then now it's going to show behind the character which looks more correct and let's add that keyframe in there so now that will look correct for this animation but if we switch to something else like idle down you can see that it's still going to have that value of negative one so if we do the ordering this way then we do need to make sure we reset that on our other animations so let's go to idle down and I'm going to take the Z index and make it zero here and keyframe it there at the start so let's create and add that so now on idle down our pickaxe shows in front of the player but on idle up it shows behind same thing with swing down let's uh add in the Z index of 0 and keyframe it so we only need to do this at the start and then walk down we will also keyframe the Z index to zero and make sure that the keyframe values actually snap to 0 0 here I'm not sure how that happened but um yeah we just need to just make sure our animation is working properly and everything snapped to the right interval okay and if we hit play then that's looking correct for walk down as well okay so let's keep going we have idle up let's duplicate that and do idle and do idle left so click on the texture keyframe and put in gather a walk left as the animation okay and then toggle it to zero seconds so that we can see where everything's at and we need to change the position of our equip Sprite also the scale by the looks of it so I click on scale toggle off link and change X to negative one and uh yeah whenever you just need the values to update when you set it manually like that just toggle it back to zero seconds by moving the timeline cursor around now let's do W for move mode Let's position our pickaxe over here so just remember where the right hand is for the animations to make sense so if the character is facing the left the right hand is behind the character so we do want the tool to show behind the character which negative one Z index value will fix okay so let's duplicate one more time and do idle right okay so check change the texture out to gather a walk right and then we just need to once again reposition everything so take the Sprite and let's toggle off the link for scale change it to one one keyframe that hit W to move and position the tool over here right around there the Z index we need to reset that to zero so let's do that and then keyframe it okay and the pickaxe can be right around there uh we might actually consider like rotating the pickaxes down on these Left Right animations so that it's not right in front of the character's face so we could hit e to go into rotate mode rotate it something like this uh you can even hold Ctrl down if you want to snap it to 15 degrees W to move it down and let's move it down there yeah maybe we need devoted it more so I'll snap another 15 degrees move it down with W okay so that should work out pretty well just click on the keyframes and make sure it got all the values and it did so let's make the idle left now match that so go to idle left so we'll take the rotation of this I'll hit e let's rotate it 30 degrees to the left so that's negative 30 and then W to kind of position it so position it like that so idlew right has it there idle left has it there and that should work pretty okay so now we just need to repeat the steps for our other animations swing left up right and walk up left and right so let's start with walk here so I'll go to walk down let's duplicate this so I will call this actually walk up so for the texture we want to change out gather we'll walk up put it there so just like with the idle animations we're going to need to adjust the position of our equipped Sprite here as well so let's make sure once again recording is enabled so that you get the auto keyframing let's hit W to go into move mode and position our tool over here to the right now of course we need to flip its direction as well so the the tool is facing out to the right so let's go to Z index and I'm going to change that value to negative 1 here hit enter to update that just toggle the timeline to Time Zero okay let's get the tool further over here to the right then we're going to need to reverse the scale as well so I'm going to turn off the link in the inspector and let's take the scale to 1 1. okay and I'll be adjust the timeline to the zero second there so we get the tool to adjust its position let's move it with w and let's see I think for the walk down we just kind of had it at that standard rotation of zero degrees so we'll just do the same thing for walk up as well okay so there's our starting position now if we go over to here we just need to set the next position okay and here we'll have the position set as well something like there and then the last position over here to the right we also need to take the Z index and set that to negative one so that our tool hides behind the character visually so let's go to the value here and the inspector Put negative one reset the animation hit play and let's see how that looks so that's not bad right there it's pretty consistent with our walk down animation just reversing the direction so we can leave it like that for now okay let's do walk left and walk right now so I'll go to walk down and duplicate that we'll make this walk left so for the texture of the body let's take walk left dot PNG and put that in okay and then we can hit play for the animation and see where we're at and what needs to change so in this case the tool is going to hide behind the player so we need to change the Z index to negative one again and you can really use whatever value you want for the Z index here as long as it's a negative value or hide behind the player's value of zero and having it set to something below negative one might actually be preferable because then you have that in between value if you ever need to stack more than two Sprites on top of each other it won't be an issue for this tutorial but just keep that in mind that this is an ordering thing and you can have multiple objects not just two or one object so anyway we need to reposition the tool so I'm going to hit W to go to move mode Let's put this over in front of where the player should be there and I can hit play for the animation to get that Z index value to update okay now we just need to update the position of the tool to wherever the player's hand is so it looks okay at zero seconds let's jump to the 2.2 seconds frame and let's move it back here since the right hand is going to mirror opposite the left hand let's go to 0.4 okay and we actually are going to want the same value as here at zero seconds so that's negative six and three I can just manually type that in for consistency Okay negative six three and then let's go to the final frame here at 0.6 seconds and position it there as well so now if we hit play there's our walk theft animation we can duplicate that as well for a walk right animation so for a walk right let's change the texture for the right texture of course and we're going to need to reverse the scale on the pickaxe so let's toggle off the link and make the value 1 1. okay so now it's facing the right move the position of the tool to right around here for the first frame and let's keep going forward so here we need to move the tool right around here the next one same position as the first frame and let's see if those values match you can of course just manually change the value seven for the pixel uh pixel X and then the last frame as well we'll just go right around here okay let's hit play for this and uh not quite right so frame zero let's change the Z index back to zero or a positive value so that the pickaxe is going to show in front okay and then we just need to position it on each of the frames to make sense so right around there here we can move it down and there we can move it there as well but uh for our idle frames I believe we gave it a rotational value let's see I don't write idle left so yeah 30 30 degrees there and we would want that to probably be the case here for idle left as well so I'm going to put negative 30 here for the rotation on idle left and let's try to make it consistent across our animations so that'll be our idle left our idle right and let's go to walk left and set the rotation here to negative 30 and let's see do we need to change the position of the pickaxe more not too much but maybe a little bit just update it on each frame until it looks good to you okay and then let's go to walk right let's set the rotation to 30 degrees positive okay and here we're going to need to reposition things so let's move the pickaxe next frame move the pickaxe and here remove the pickaxe and put the pickaxe there so there's our walk right looks pretty okay walk left all right walk up walk down and of course we have the idle animations okay so basically we just need to repeat the same steps with swing up down left right so it's going to be very very similar here let's duplicate the swing down animation to make swing up and then let's take the texture and put our swing up animation in the texture slot of course here we're going to need to make the Z index negative we're also going to need to reverse the scale on X so scale to 1 1 okay let's see where we're at and let's position the tool over here to the right and then swing up still going to need to take that position over to around about here and then finally this Frame is going to be a little bit trickier we need to first set the rotation to something good so let's yeah I think if the hands right around there then this would probably be a good rotation so let's get the rotation maybe something like that then move it up here maybe it needs to rotate a little bit more to the left yeah okay that that looks okay so it's hard to see the pickaxe if it's even visible at all but we can definitely see that the hitbox is there so maybe we just position it for the sake of the hitbox right there in the middle all right and let's see our second frame is okay let's hit play on this and see if that's going to work for us the second frame I think needs more of a rotation back so I'm going to put it like that let's move here or maybe that's too much just kind of tweak it as you want first frame yeah we should rotate that as well so maybe it can be here and then go further it back and then we go forward let's try it in play okay maybe too much rotation initially let's put it like that hit play and yeah I think we can work with that we can always come back to this later if uh we need to tweak it so let's duplicate swing down again and we'll make that swing left so of course we're changing the texture out so let's get the swing left animation pop that in there and in this case uh the hand is behind so we want the Z index to be behind as well so set negative five here and then let's position so here let's position the pickaxe let's rotate it okay so right around there and then the next frame let's rotate it oh we want it to actually rotate back so let's put it right there and then the final frame let's rotate it forward so that it hits the ground in front of us and something like that could be pretty okay so let's hit play okay and that's looking all right so let's duplicate this again for swing right so swing right change the texture out to the swing right texture we're going to need to reverse the scale so scale 1 1 and then let's rotate it and position it in the character's hand go to the next frame rotate it backwards for the swing and position it in the hand and the final frame rotate it forward so that it hits the ground and then position it in the hand okay maybe we overshot that by 15 degrees so right around there okay so let's hit play for our swing right okay let's test our swing left those are looking all right for right now so basically we have all of the 12 animations set up here what we're going to need next is a animation tree so if I click on player and add a child node animation tree in our animation tree and the inspector we're going to go to tree root click on the drop down and do state machine next be sure to set up the animation player and the inspector for animation tree so assign the animation player so next we can right click on the graph and add in three blend space 2DS for our three sets of animations so the first one is going to be idle and then we'll right click playing space 2D and rename this to be move or run let's see what have we actually call it block so let's let's make it walk for consistency and then right click blend space and we'll rename this to be swing so when our animation Tree starts we want to start off in the idle animation and then we want to go to the walk animation if our character is moving or back to idle if our character is not moving we also want to be able to go to our swing animation if the swing button is pressed so let's create a connection to swing and we'll create a connection back also to idle or walk so walk to swing and swing to walk for controlling the logic here you can create a purely code based State machine that will change the animations for you or we can also set up Auto Advanced conditions so these conditions basically encode we just set something like idle when we want to switch back to idle as a Boolean or is walking if we want to switch back to walk and we can have a condition like swing pressed when we want to transition to the swing animations so you can have the logic actually occur inside of the animation tree and that's what we're going to do for this character's player logic so for going back from this wing state let's change the switch to at end and the mode is going to be Auto and the condition we can set is moving for connecting back from swing to idle let's do something similar let's change the switch mode to at end and the condition Auto and we'll say the condition is idle for going to the swing animation let's set up a condition which is going to be swing and I'll set that for both of the connections between walk and swing whether we're in the idle state or we're in the swing state for idle to switch to walk we have to set the condition is moving and for walk to go to idle we'll set set up the condition item now you would think that having a condition is moving if you wanted to switch back to idle you would just have not is moving here but as far as I've tested that doesn't work you have to have separate Boolean conditions for each of them you can't just reverse a Boolean condition here so we have to have two separate variables which is a little annoying but it shouldn't really be a problem okay so anyway to go quickly over it idle to swing uses Auto swing condition walk to swing use a swing condition swing to walk is is moving is true swing to idle is idle is true and idle to walk is is moving is true and walk to idle is idle is true and the only other thing is that for the swing to return it has to wait until it's at the end of its animation in order to exit its animation okay so let's go into the player script and let's set up some basic code to set those animation parameters so if we're going to be changing the animation treat parameters then let's get access to the animation Tree on ready VAR animation tree it's a type animation tree and we're going to say equal to dollar sign animation tree which means we go in the hierarchy we find the node named animation tree and we assign it to this variable animation tree when the script starts on ready so basically now we can set parameters on animation tree so let's make a new function and we'll say update animation parameters so if we want to set those parameters up we can go to the inspector of the animation tree expand expand parameters and you'll see those conditions that we typed in are actually going to appear here okay so now to actually set these parameters we have the parameters set up inside of our little animation tree if you look at the inspector and you expand down to parameters conditions you'll have these booleans that we set up idle is moving in swing so if you right click on these you can copy the property path so if we go into the code and hit Ctrl V you'll see the path appears with parameters slash conditions and then the name of the condition to actually set it let's delete that for a second and type in animation tree which refers to the animation tree node that we are referencing up here at the top and then in square brackets put in parentheses and then Ctrl V to paste in the property that we're trying to set so if we reference animation tree and then the path to the property that means we're setting this Boolean value here so for this value we'll set it to true if a certain condition is met and then the condition we'll use is going to be if velocity is equal to Vector 2 dot zero okay basically we're not moving then idle is going to be set to true and also at the same time we can set is moving to false and also for the if it's two equal signs to compare values we're not assigning them so let's also set is moving to false here so I'm going to right click on is moving thing copy the property path and let's do animation tree and then in square brackets parentheses Ctrl V paste in the condition and we'll set that to false okay so otherwise if the velocity is not zero then we are moving and we're not idling so let's take Ctrl C Ctrl V paste them down here and just reverse the true to false and the false to True okay so that handles those for the swing animation we need this to trigger if the swing button was just pressed down right now we don't actually have a swing key so let's go up to project project settings input map and let's add a new action so this will be I guess we'll say it's the use action so we're using whatever tool we have in the hand and then let's add a key to this I'll use f on the keyboard so just press F and then hit OK and now f is going to use our tool so let's close that okay so now we can add the check for if the use action is pressed or if it is not into update animation parameters so let's check if input and this is kind of a global object you can reference so you don't need to set it up in the inspector with an export variable or anything so we're checking if action just pressed and the action we're looking for is the use action so put the string for that so if the use action is just pressed then we'll say animation tree and then we need to put in the parameter path so if I click on swing in the inspector copy property path and paste it in so if used was just pressed then swing is going to be true otherwise we'll say that swing is false now this is like a pretty simple way of doing it we could also like have a timer where after 0.25 seconds of a button being pressed we would still say that swing is true but this should at least get us going for getting these conditions to be set now one thing I do want to make sure is that the animation tree is actually active when our player starts so we can add a ready function function underscore ready and when that happens we can say animationtree DOT active is true so when our script starts the animation tree will be turned on to active and we'll make sure that it's actually running so now for these animation parameters to actually update we still need to call update animation parameters sometime in our script so we could use the normal process function for that I think so let's do function underscore process Delta and then just do update animation program meters so let's go ahead and hit play and see if anything actually happens when we move around so as you can see visually speaking nothing's happening yet so one way we can check why that might be occurring is going to the scene view while the game's running and click on remote so in remote view we're looking at the currently open game and we can drill down to the game level and look at the animation tree of our player so if we click on that you'll see the conditions being set here if I start moving is moving actually gets set to true and if we stop moving idle is set to true so the conditions are working but the animations are not yet and the reason is that we simply haven't set up the animations inside of our blend spaces so exit the game and go back to the animation tree and take a look at the animation State machine here and we need to open up each of these blend States or blend spaces and edit them so inside of a blend space we have a 2d graph and and the animation tree will automatically please select which animation to play based on how close to the value of the nearest animation that we happen to be so if you click over here to create points that's how you add an animation to the blend space so click on create points and then I'm going to click on the far left in the center and then add a animation and we're looking for idle left so that is going to be at position zero so that's going to be at position 0 for y and negative 1 for X now we can go down here or the idle right let's go to the far right over here left click add an animation idle right for the top and bottom animations because I want left and right to be prioritized I'm going to change the max for the Y to 1.1 and the Min for y to negative 1.1 so basically if we press two directions at once it'll end up coming closer to the left than it would to the Top If our input is somewhere up here because we're putting the Y value further away than the x value anyway let's go to the top here left click add animation idle up and then down here at the bottom left click add animation idle down so left click on each point and make sure that values are correct so up here this one's zero 1.1 that's correct the bottom one is negative one so we want to pull that further down to be negative 1.1 and then on the far right we have one zero and on the far left we have negative one zero so now we set up the other blend spaces just like this so go to the walk blend space and we're going to put 1.1 up here at the top negative 1.1 at the bottom for the Y values let's add in the animations with create points left click add animation so we want walk left over here on the right is walk right and then at the bottom walk down and at the top walk up okay let's go back to the root do the same thing for swing so set the Y Max y Min to 1.1 and negative 1.1 create points add in the animation so walk up walk down walk right and then over here is going to be walk left okay now these blend spaces how do you set the x y values inside of them so it's very similar to how we set up the animation parameters if we click on animation tree you'll see that there are blend positions for the idle swing and walk blend spaces so we simply need to set the blend position for each of those as we update our character script and how we're going to do that is we get the direction that our character is moving and we set the Blends and we set the blend position to that normalized Vector Direction so right click on idle blend position copy property path which is going to come in here to update animation parameters so we'll do animation animation underscore tree square brackets quotation marks paste in the path to the blend position and we're going to set that to the input Direction so up here in physics process we were getting that direction as a local variable let's actually make this a script-wide variable so I'm going to remove the VAR here then I'm going to go up to the top and type in Far direction is a type Vector 2. it'll default to Vector 2.0 before we start doing input and we're going to update it every time in this physics processor we do also need to remove this typing of the variable since that's now up here at the top and once you do that it should go away so we're setting this variable whenever we update our physics process now and this is already a normalized vector so we just need to take the direction and set the blend position equal to that so equals Direction and we need to do that three times for swing and walk as well so let's copy this paste it paste it and for the parameters we can just type in here swing and down here we'll do walk so save that whenever the direction is updated we're basically also going to update the blend position for all three of these blend spaces so if we hit play now we can see that the the animations do change but it doesn't entirely appear to be correct here so let's check the animation tree and make sure that everything's set up correctly so in animation tree let's edit the idle blend space and let's look at each of these nodes so down here is idle down idle up idle left and idle right okay and let's check walk so we have walk up walk down and this one should be down here to negative 1.1 okay up there is positive 1.1 over here is walk right walk left I think we actually need to inverse the walk up and the walk down since up is actually down on the y-axis so this should be walk down and down here this should be walk up so you can just change that in the inspector okay let's do that for all of them this should be idle down and this should be idle up and then swing this should be swing down and then up here should be swing up at the bottom oh yeah of course also for the blend you want to set that to discrete we're not trying to blend between the values here we're trying to have it once again like the animation player animations we're trying to instantly jump to each of these values so make sure that you blend spaces are set to discrete mode that's the other problem that's occurring right here so discrete discrete and the walk should be discrete as well okay let's hit play again and see if that's any better so left down right up okay the walk animations are switching correctly and whenever we let go we're actually switching back to facing the left on the direction and that's because it's setting the direction to Vector 2.0 so as a condition for setting the direction we should actually put in here if direction does not equal vector 2.0 so if we don't have any input then we shouldn't update the direction parameters for the blend positions so now if we hit play and we do you up down left right that should clear up the idle animations so that is looking much more correct here another minor issue we need to clean up is that when we press the F key to do the swing but we're facing left and right it actually plays the walk animation but up and down walk fine that's simply because I messed up and I set the walk animation inside of Swing instead of the Swing animations so if we click on the left point over here we can see the animation is set to walk left that should of course be swing left and over here on the right it's set to walk right which it should be swing right okay now with that if we go in here we can test all four directions swing left swing right swing down swing up okay so the animations for our character are pretty much working correctly one thing I want to change though is that the character moves way too fast so we're probably gonna slow him down by at least half so let's jump into the player script and I'll pull this down here let's go to the top and I'll make his base speed a hundred let's try that make sure it updates in the inspector as well since this is a export variable let's hit play and test that out one more time okay yeah this seems much more like an appropriate speed for the character we could even slow it down a little bit further and make it something like 80 but I think that this is uh pretty good for testing now what we need to do is that when we swing our pickaxe if our area 2D comes into contact with our resource nodes such as the rock that we want to actually Harvest materials from The Rock so on our hand equipped node we're going to want to create a new script that uses the area 2D and detects resource nodes when it comes into contact with them so let's take the hand equipped node 2D I'll click the add script button and let's create that in character slash hand equipped.gd okay so inside of here on ready we're going to want to get access to our area 2D so at on ready for let's call this variable something like equip hitbox which is of course going to be a type of area 2D and we'll look for dollar sign area 2D to find the area 2D under the script as the node we can use okay so in our hand equipped script I'm going to get rid of all the spoilerplate code except the extends node 2D part I'm going to click on area 2D here let's go to the node tab which is next to inspector in the top right and we we want to choose body entered here so in a physics body enters the area we'll check if it's a resource node type and if so we'll run the Harvest function on the resource node and get some materials out of it so let's double click on body entered here and we're going to connect it to the hand equipped script so we should see this new function come up here when you hit connect and you can click on area to D and see where we have the signals connected to and you can double click to actually jump to the function inside of the script if you ever need to so we're going to check if the type of body that entered was a resource node so let's go over to the resource node scene and we want to attach a new script to this resource node so I'm going to click on the add button for a new script I'll call the script resourcenode.gd because we'll use it for other types of nodes not just the rock so let's create that and we'll give it a class name so that we can reference it by its class name so class name is going to be resource node we'll get rid of this extra code down here and just to give it something let's give it a export bar and let's call it a starting resources as a integer and we could default this to something like let's just say one so by default a resource node will have one resource and later when we run out of resources we'll remove the node from the scene so if we click on resource node here and go to inspector we can see our starting resources value so to go along with the starting resources we'll have another variable current resources which is also going to be of type ENT and when our script starts so function ready we'll take current resources and set that equal to starting resources so basically when we add a resource node to the scene whether that's when the level loads or any other time we instantiate it we're going to start off its resource count with the starting resources for this node okay so we'll come back to the script and add more stuff to it later let's go to the player node and jump into the hand equip script so inside of this on area 2D body entered we want to check if the body is of type resource node so we can check here if body is resource node and we can do this by specifying the class name because we actually created the class name in the script so resource node is something we can reference and if the body is of type resource node then we want to harvest from the resource so when anybody enters our hand equipped area 2D for colliding with resource nodes we want to check if the body is of type resource node so we can do that by doing if body is resource node so if the body is a resource node then we can call any functions from the resource node class on it so we can do let's say body dot Harvest and then we'll give it a harvest amount so when the item equipped to our hand comes into contact with a resource node we want to check if the tool is capable of actually harvesting from that resource node so in order to do that we also need to know what kind of tool or weapon or whatever we have in the hand is actually equipped to our character's hand so let's add a export VAR up here and we could say equipped item so what we're going to do with these equipped item resources is that when we're in game we're going to change it to whatever the texture of the tool we currently have equipped to the hand is so whenever we change the equipped item up here basically we're updating it across our game and then we'll be able to use the right tool to harvest the right nodes now I also thought about it for a while and we can go a step further than this by also making it so that some of that code will run in the editor so when we change the equipped item in the editor we can also update the texture immediately but in order to do that we would actually have to have the script attached to the equip Sprite node but looking through our animations all of the properties that we're changing are already on that equip Sprite texture so if we look through here there's actually no real need for the hand equipped node at least currently so we can actually just move the script to the eclipse right node make it extend from a Sprite 2D and then we'll be able to write that code that can update the texture inside of the editor as well so that will just be one way we can actually make it a little bit better so what I'm going to do here is take the equips right node and just move it outside of the hand equipped node but I'm gonna have the animation window open here so that I can just watch and make sure that moving things around doesn't destroy uh the animation setup here I think in the past it might have caused some problems but now let's go ahead and move equips right up here and you'll see that equipped Sprite still shows up there even though we moved everything up so it's not at the same position but it's still being referenced by name so if we hit play here our animation still works completely you can see that the hand equipped node we didn't really need it for anything so let's take this script uh the hand equipped and I'm going to let's move it to the equip Sprite so you can just drag and drop from the code editor right here and drop it in there and then let's just rename this equip Sprite to be hand equipped first I'm going to delete the hand equipped node so let's get rid of that and then up here I'm going to rename this to be and equip once again having the animation window open to make sure that it handles the renaming of things there so once again in the past like good O3 I think that uh when you rename stuff like that it would actually break your anime Nations but now it seems to handle things really nicely and keep up with the new naming of the nodes so that's super nice so what we want to be able to do now with our hand equipped node is to be able to set our resource here so right now we can drop any resource into this node but that's not what we want we want to create a custom resource which is a different type of script than a node script because it is not going to attach to a node in your scene it's actually going to be a kind of a class you can create objects from and those objects sit inside of your project rather than inside of your scenes as an attached script so you can almost think of it as a scene you can instantiate except instead of that it's just a instead except instead of a scene it's just a data object so I have an items folder created in my project I'm not sure if I created that earlier on screen or not but create a folder for items and then we can right click into here and do a new script and we're going to inherit from resource course this time and what we'll see here is equippable item dot GD so let's create that and double click on the script so we extend resource here you can think of this more as a data object rather than a script which enhances what a node can do so it's not going to have the process functions or anything like that if you're used to Unity it's very similar to a scriptable object so for our resource here I want to give it a class name so we can be very specific about what kind of item can be equipped to the hand so let's give it class name equippable item so anything that is equippable whether that's a tool or a weapon will inherit from this okay and then we can give it some data fields so I'm going to do at export VAR and let's start with a texture of the equipped item and this is going to be a texture 2D okay and maybe we also want a display name so I'll do at export our display name and that'll be a string so the reason you might have a display name variable is that how it actually shows up in game how you want the text to show whenever you reference the item could be different than how you have the name of the resource saved into your project you might have like underscores here but that would look ugly in game so having a custom string field for that can be a little helpful okay so now just save that file and now if we right click on the items folder we can go to new resource and look for the type we just created equippable item so it extends resource it's equippable item from the equip item.gd script so double click on that to create it and you'll see that this new resource saves us a DOT Tres file so it's kind of similar to saving a node scene into your project so you can use it across your game except instead of instancing it you're just referencing this store of data so let's give it a name we can just give it a test item for right now our actual tools are going to have another class that will build on top of a grippable item and have some extra stuff attached to it but let's just create a test item for now hit save okay so if we double click on the test item.tres you can see in the inspector our display name and texture for this resource so for the display name I'll just say test item and for the texture well first let's look at 2D view let's use something different than the pickaxe that's here standard I'll go to tools and let's use the hammer.png so hammercopter.png just drag that into the texture slot okay so now you can kind of see how this is setting up we're giving d details about what an item in our game actually is then whenever we need to equip it we have these data fields we can use so let's save everything and click on hand equip and we could actually drag this equipped item in right now so if we go down to items you can see we can drag test item.tres into this field and when we do that nothing's actually going to happen because um right now our script is not set up to do anything with it it's just a equipped item and right now it's still set to Resource so we could have used any resource the equippable item is a type of resource but there are other resource objects let's be specific now and change this to equippable item so now by specifying that class name only an equippable item can fit this field so other types of resources don't qualify and that is Handy for managing things to make sure we have the right items actually equipped to the fields that allow them now we can reset this field and drag it in again to show that we can still set that there um I guess we could do another test I'll right click here do new new resource and just do a normal resource here so let's create that I'll just save that and then let's see if we can drag that into the field we shouldn't be able to so I'll drag new resource.tres into here and you can see it doesn't qualify anymore so it keeps the resources that don't qualify out okay let's delete that new resource we'll never need that and now we want to make it so that when we set a new equipped item we actually update our texture on our Sprite 2D node which is the hand equipped node now so if we go to the end of this export line and add a colon then we can add Saturn getter functions to this property field so we want a set and when we do a set function we're going to need the new equipped item as a parameter so new um or next item so as the parameter I'll type in let's say next equipped okay give it a colon new line and now we can actually write the code so when we set a new equipped item what do we want to happen the first obvious thing is that we want to take the equipped item field and set that to the next equipped so the next equipped is the so the next equipped is the new item coming in and the crypto item is the field that is set in our script and then the equipped item is the field set in our script so after we change the equipped item this field in here we want to update the texture as well so we're going to take the texture and remember this is a Sprite 2D node now oh well it should be a Sprite 2D node but we haven't changed the extend up here so change this to Sprite 2D okay and now there should be a texture field if you want to see all the fields that are attached you could write it like this self dot let's say texture and then it'll automatically know what we're dealing with a Sprite 2D node so we should be able to access this texture property so let's do self.texture and then we'll set that equal to we could do the equipped item or the next equipped I'm going to do the equipped item because this will also verify that we've set it properly so equipped item dot texture so that's a field that we set up in our resource script the equipped item so just grabbing this field here and then we're going to set that to the texture so this book will actually already work in game if we go to 2D view you can see in the editor we have this pickaxe but if we hit play well this set of function is going to get called so we switch to the Hammer already and you can see because of the way we set up the animations it still works with this tool um because we're just changing the position scale and rotation on the Node so it's going to basically work with any tool we equip it's going to function the same way for this animations now how do we get it to work in the editor well if we go up to the top we can write this annotation at tool which means that your code is going to run in the editor as well as in the game now you can specify as we'll do later on that certain code will only work in the end game and you can also specify if code will work in the editor but by default if you have this add tool it's going to run in both so for the tool scripts to work what you need to do is close the scene and then reopen it so let's go ahead and reopen the player.tscn scene and you'll see that now the tool has been updated to the Hammer texture from our test item so that basically means that whenever our script loads the set function is going to be called and Whatever item we have equipped we're going to grab the texture from it so this works both in game and in the editor so if we go hit play well you can see of course that we have that tool equipped before now that is now set in the editor by default but you can see before we added the add tool that that was working so yep we don't need to do anything like on ready to set this now it's something I do uh want to kind of test for myself here is uh if we can have this tool script go ahead and let's say update another Sprite so I'm going to add a Sprite 2D node as a test and let's uh put it underhand equipped and then I'm just going to get that as a unready VAR or no I guess let's make it a export bar so at export VAR Sprites 2D which is a type of sprite 2D and this will be equal to well no we're going to set that in the editor sorry okay so export far Sprite 2D will assign that to the Sprite 2D node here and what I want to do is take the Sprite 2D dot texture and also set that to the next equipped dot texture so let's see if this will run in the editor I'm going to grab this node hit W to move it out and let's come out here so I'll save the node and let's close the player.tscn yep save and close and then reopen it and let's see invalid set index texture on base nil so did we set this by 2D node yeah we did yeah so I thought it might actually work like that uh where you can't really access other nodes they do specify in the documentation right here this but code from other nodes doesn't run in the editor your access to other nodes it's limited so uh basically if you want to add tool script to work then seems like you're going to need to attach that to the node where you're actually changing the texture files so that's that's why I changed it earlier by removing the node 2D and then just moving the script into the Sprite node okay with testing so let's get rid of that and this bit right here and just get back to what we had before but what's important is that our equipped item thing is actually working here so anything else we need to set up whenever we change the equipped item we'll just add to this set of function so for instance in our equipped item if we're like setting the attack damage then we do something like attack damage equals whatever is in the equipped item dot attack damage and that's how we'll keep our scripts updated with Whatever item we have equipped okay so the next thing we'd probably want to know with our equipped items is what type of equipped item are they actually so we could make that typing another field under the equipped item or we can make the typing tie to a class specifically so we can extend the equipped item class and let's say make like a tool class or a pickaxe class and then inside of that class we'll set up a function for when the body enters our area 2D we interact with a specific type of node such as a rock and then we'll be able to harvest from that node okay so now let's go to items and create our new script we're going to inherit from equippable item with one p and uh let's start with something like a harvestingtool.gd script um the reason for this is that there'll be multiple tools like pickaxes and Hammers and maybe like a shovel later on which are all going to harvest from different types of nodes so a lot of the code we can just rewrite there's a lot of the code we can just write here inside harvestingtool.gd we might not even technically need to create separate scripts for a pickaxe or a hammer so let's start with this create and then we can edit our harvestingtool.gd so every harvesting tool is going to have a harvest function which is going to take a resource node and this is going to do something with it we'll pass for right now I guess we'll add something like a damage variable at the top we could call it damage or we could call it like amount to harvest so let's say at export VAR I'll say Min damage and let's make that an end and default it to one and then at export VAR Max damage and we'll make that an end and default it let's say to one as well so when we actually Harvest we can randomly generate between these two values to make it a little bit more interesting so sometimes when we Harvest a node we get one or or wood or whatever and then sometimes we'd get more up to the maximum amount uh depends on exactly which tool we have equipped okay so let's save that and then we'll create a new harvesting item so let's do new resource so we're looking for a okay we haven't added the class name so back out of that class name harvesting tool okay now let's right click new resource harvesting we got harvestingtool.gd and let's create this as copper pickaxe dot Tres yeah okay we can start with that for now so if we click on our harvesting pickaxe we can see we have the display name so we know this is a copper pickaxe so we're gonna do copper pickaxe and then we gotta set the texture so under Tools orange voyag and the pickaxe copper here and then our Min damage Max damage we'll leave that set to one um now for a second let's jump back over to the hand equipped script so whenever our area 2D has a collision with a body then what we'll basically do is uh we'll check if the equipped item actually has a function to interact with a body so let's do something like if equipped item dot has method and let's say something like interact with a body here as the name of the method so doing it this way we don't necessarily check the exact class of the equipped item but we just see that whatever script we have attached to it actually has this function so we just need to make sure that if we're creating different types of tools or weapons that anything that is going to interact with a body deal damage or whatever actually has this function here so and just a different way of doing things so if the uh equipped item has the function then we're going to run it so equipped item Dot interact with body and we're going to pass in the body okay and then that basically passes everything over into our equipped item script so this basically passes the flow into whatever kind of equippable item we have that is going to use the interact with body function so a harvesting tool is going to interact with bodies so let's go to harvesting tool and um yeah I guess we'll write that function down here function interact with body it's going to take a body okay and what we're going to check on the body is if it is a resource node so let's go back to Resource node up here so we do have the class name resource node so we'll check if the body has that so in harvesting tool we'll check if body is resource node then we can continue and I think for right now it would be a good time to test print interact with resource node okay so we can basically Run the game and see if that will actually work there so let's say play and let's walk around and watch the output console okay so let's try swinging at it okay so currently it's not doing anything um let's see in the player we have this test item uh the test item is still an equipped item it's not what we actually want it's not a harvesting tool so you can see that the test item which is just an equipped item doesn't actually do anything when it interacts with a um when it interacts with the body let's try with the copper pickaxe drop that in there so it updates here let's hit play and let's go walk towards that uh resource node and see if we get the interaction to occur I'll swing at it still technically doing nothing all right so let's kind of debug that a little bit I'll figure out what's going on so first let's jump into equipped item and let's see if we're getting here let's even see if the area 2D body entered is running at all and then let's add in harvesting tool add this little bit here where we'll see that if we're checking if it's a resource node so if we hit play uh we can come down here and see that nothing's still happening and I just noticed what's actually going on so our area today isn't actually connected to our hand equip of course that would be because we changed nodes so we need to go to the node area 2D next to the inspector and we need to take body entered and we need to reconnect that to the hand equipped node so connect that there okay it's going to use the same function but now the signal is actually connected so signals can be connected like this or it can be connected in code now let's hit play and see how far we get with our um interaction okay so we moved there and the body is probably going to be something like itself so let's see what item is that actually so our area already interacted with body probably the character's body um so we're just going to pass from there and then we can continue okay so now we're going to check if the body is of a type resource node so it is passing into harvesting tool so let's continue from there and let's see did we get the output we did not because I checked that the body was not of type resource node so let's watch the output still and I'll go back to the game and let's actually walk towards those resource nodes so when we get here we get interact with resource node up here interact with resource node and here interact with resource node now of course we don't want the interaction to occur all the time we only want it when we're actually swinging the pecx so that'll be something we set up in a minute um but so far we actually are getting those interactions which is good so next if we know that we are interacting with a resource node we want to check what type of resource node the body is or what tools it can be harvested with so to do that let's create some classifications for what type of resource node our VOC actually is so obviously we want to say it's a rock so what we can do is create a resource node script which will identify our resource known as a rock and then create a field drag it in here say that this resource node is a rock okay so now in our resource types folder let's right click new script so let's create the script for our type and what we're going to call it is something like a type of I guess we'll just say node type dot GD okay yeah we can do that and maybe resource node type actually so resource underscore node underscore type okay now we'll double click into there let's do class name here which is going to be resource node type save that and then we can right click in our types folder and start actually creating those resources so new resource resource node type so the first type we'll create in here will just be a minable type so this could be anything from a rock to a or vein or just anything you can swing a pickaxe at if you want to be more precise you could call it rock type or an or node type or ice crystals type whatever but I think this will be specific enough for our purposes so let's hit save here okay now we have this type we need to assign it into our resource node Rock tall so in resource node Rock tall let's add a export variable at export bar uh no type and we'll say resource node type as the resource that we're going to set here so Ctrl s to save that now we can click on our node and we can assign the node type here um we could actually make this an array even if we wanted to um having multiple node types per nodes so we'll just dragging my mole.tres into here so now we can just check if we're interacting with a node if it's a minable node then we'll be able to mine it with a pickaxe so let's hit Ctrl s um and then let's go back to the harvesting tool and here we actually are going to need an array because a harvesting tool like a pickaxe may be able to interact with multiple types of node types so let's add a new export bar export bar let's say affected nodes and this will be if I'm doing this right an array of a resource node type okay and then save okay now let's go back to the player scene and we'll look at this so we have the affected nodes here in the copper pickaxe.tres so we can actually edit it here so let's click here and add one node type and that is going to be minable.tres okay cool um so that should be all we need there now back on the resource node as I mentioned we can make this an array as well so just in case we ever need to have multiple types per node let's let's do that as well so anyway and then square brackets of resource node type and then we'll change node type to node types then we can just take the array and expand its size to one drag in minable.trs into here and that's all we need to do to set our resource node as a minable type and then specify for our copper pickaxe and items that it can affect minable resource node types so what we'll do now is whenever we have a match then we'll allow the pickaxe to interact with the minable nodes Like a Rock so in our harvestingtool.gd we're going to check if the affected nodes or affected types I guess we should say yeah let's call that effective types Ctrl s and I guess we need to reset it here so we'll just add everything back in uh to the array we'll check that if whatever's in this array matches at least one in the resource node then we'll actually interact with that node in this case that's going to mean we're going to run the Harvest function on the resource node okay so what we can do is Loop through all the affected types and see if the resource node matches any of them so for type and effective types and uh let's make sure that has one p there oil check that's a body dot node types dot has okay since that should be an array and we'll check if that has the type that's going to be an if statement so if the body node types has the type then we're going to basically allow it to interact with the body so we'll print let's say match found at type and let's do type dot resource name and on the Node on plus body dot name all right okay let me expand that so you can see the whole line here so we check for all the types if the body has any of those types assigned like mineable then we'll match the type and then we can do something with it like do resource node.harvest so we'll probably move the Harvest function actually into the resource node instead of the equippable tool so let's see if that will actually run first let's uh walk over to our resource notes okay and then we have matchbound.type okay it didn't actually give us a name there on resource node Rock tall but we are getting those matches so that's good so why doesn't this work can we do just plus type then let's see if we can do um string on the type so just converting it into a string will that work and then let's walk around let's get that no that's just the resource ID so what we might want is a display name on the resource node type so let's give all of them export bar display name which is a type string okay and now we can click on minable.tr yes and just say minable okay and then in our harvesting tool we just want to do type Dot display name okay now let's hit play now let's walk over here and now we can see match found at type minable on resource node Rock tall okay so that's good we can basically harvest the nodes now we just need to create the Harvest function so as I mentioned I'm going to move the Harvest function over to the resource nodes since every resource node can be harvested and I guess it makes more sense to do it at that level so let's do resource node.gd and I'll paste in the Harvest function we don't need to know the resource node we're already on the resource node but what we do need to know is amount and this is going to be a integer so we need to know how much we want to harvest from the node okay and what we'll do is we'll take the current resources and subtract so minus equals the amount and then once we run out of resources we do want to remove the node so we can do that as a Setter function so let's do set value so we're setting the new value if value is less than or equal to zero so if the value is less than or equal to zero we're going to U 3 on the Node which basically just means remove the node from this scene so our Harvest function we even move the resources if so if the resources drop below zero it's going to remove it from the scene and later we'll also add in like an animation here so that when it is removed it'll you know be more obvious than just disappearing immediately okay um now uh back in harvestingtool.gd um we already know that it's matching so we can remove this kind of debug unless you want it to be there I think you could study like uh print debug and then let's uh come down here and do body dot Harvest and we're going to do Harvest on the amount so we have the Min damage and the max damage we need to do a random integer value between those two so let's do Rand I dot range or underscore range and the range is the Min damage to the max damage so let's give a comment here if the body interacted is a resource node that matches one of the affected set for this tool then the resource node will be harvested between the men and Max amounts for this tool and I'm actually going to take this but here let's do a control R and do a find and replace so we're going to take Min damage and we're going to replace that with um let's say Min amount replace all and let's also do Max damage and replace with a max amount replace all I think that's just a little bit clearer we're not exactly damaging a node though that makes some sense we're just harvesting it so I'm going to use minimal and max amount as the awards here so to finish that comment between the Min and the maximum all right cool okay so let's test that out in our player scene we can see that the copper pickaxe has a Min amount and a max amount of one so every time it hits a node it's going to generate exactly one resource which in this case just means removing it from the node so far and then the rock resource has a starting resources of one so if it gets hit once it should remove from the scene let's hit play and test that out so let's go up to our nodes I'll run into it oh boom it got harvested and we can see the debug message there in the console let's Harvest some more resources boom harvested harvested now uh that didn't really do anything yet it's just decreasing an integer value but now that we know that we're interacting with it we can actually generate the resources pick them up add them to the player's inventory and then we'll kind of be on our way to getting this resource harvesting thing going so let's create um let's say another folder in objects and we'll call it pickups so this will be anything we can generate that can be picked up into the player's inventory um like a rock or piece of wood let's do right click on objects new folder and we're going to say pickups here enter for okay now let's right click on the pickups folder and do new I guess we need the GD script first so this is actually going to be a node because the pickup is going to exist inside of the scene which will add a resource to the player's inventory but it does need to have a scene presence so we'll add the script here and we'll say pickup.gd and this will inherit from I guess static body 2D since it will be a physics object in the scene so let's create that and we have this pickup.gd script okay so in the pickup.gd script let's give it the class name pickup okay save that so let's create a new scene now for our first pickup scene new scene other node and let's look for pickup since we created the class name we can just create it right here create our pickup go to 2D View and our pickup is going to need a Sprite node so let's right click ADD child node Sprite 2D and let's rename our first pickup to be pick up underscore Rock let's hit Ctrl s and we'll save it in our project so let's save it into the resources pickups folder pick up Rock dot here save it and our static body is also going to need a collision shape so let's right click here ADD child node Collision shape 2D and our shape is just going to be a circle shape okay so add that in now we need the Sprite Sprite 2D let's go up to our art and let's get a object for the pickup resource so I have it under the resources folder Rock item let's drag that into texture and now let's make the Collision shape actually match the shape here so Collision shape click on shape 2D shrink the circle to oh right around there there I guess here is nice so a radius of four and now we'll have I'll pick up inside of the scene okay so with our pickup whenever we harvest the resource we want to generate that many pickups so that our character can pick it up and add it to his inventory so let's go to the resource node script and we're going to add in which pickup we want to instantiate so at export bar pick up type and this will be a packed scene so we'll save that click on resource node and we need to assign our pickup type which is of course pickuprock.tscn so drag that in there so now we have the pickup we're going to spawn when we Harvest so let's add in the spawning above when we actually decrease the amount we'll create the pickup and then we'll decrease the amount okay so let's run a for loop on spawning the pickup for the amount of times that we are actually generating resources so we can do four in in amount so basically we'll just run code the amount of times and then n is like which instance of running through this Loop it is starting at zero and going up to amount minus one so we're going to want to spawn a resource every time we do that so we need to have a spawn resource function so we'll make that spawn resource and that's going to mean we're going to create an instance of our pickup type so far pickup instance equals and then our pickup instance is going to be of a type pickup and that's going to be equal to pick up type Dot instantiate as pickup and uh for right now we'll just start with that so we have Harvest we're going to spawn a resource respond the resource it should be in the scene oh we do need to add it as a child to something though so let's take a look at our uh 2D game level we can see that our resource nodes are going to be under the game level so we can get the parent and add the pickup to the parent game level so let's get reference to the payment but we only need to do that once so we'll do something like at on readyvar uh level parent equals get parent okay okay it looks like that should work so we'll take the level parent and we'll add a child and the child is going to be the pickup instance so whenever we spawn a pickup we add it to the level as a child so that would mean the in the hierarchy if we look at game level it'll be under here and show it somewhere down there okay let's hit play and let's harvest the rock so I'm going to come down here and boom okay now we got the the pickup to actually show up here if we go up here the next pickup shows up we can actually check the remote view look at the game level and we can see our nodes are actually spawning down here and then we can add another one okay look at a remote View and yeah we have three pickups showing up there now those are all spawning at the zero zero point but where we want them to spawn is wherever the resource node it is so uh let's jump into the resource node script spawn resource we want to take the pickup instance dot position and we want that to be equal to the position of our resource node okay save run again and let's Harvest those nodes we come down here okay we got the pickup to show up down there hit this pick up shows there pick up shows there now that's not very interesting if the pickups just show right on top of the node so what I actually kind of want to happen is that these pickups are going to launch themselves away from the resource node and once they've landed on the ground then we'll say that they can be picked up so in the pickup script let's disable the Collision shape until the pickup has actually landed on the ground so in the pickup let's do at on ready far uh Collision shape which is going to be a collision shape 2D and that'll be equal to dollar sign Collision shape 2D when we start the script on ready I want to take Collision shape and so what we're going to want to do is that whenever we create a pickup through the resource node script we'll kind of kind of want to launch it disable its Collision shape move it a bit and then once that's done we will um re-enable the Collision shape so that the pickup can be picked up by the player so inside of our pickup script let's create that function so that we can move the pickup or say a function launch which is going to take a let's say let's call it a velocity which will be a vector 2 having a direction and a magnitude and then a time let's call it move duration so that will be a float so because this is a static body we're going to have to set up our movement all through code so let's go up here to the top and let's add in some variables I'll say variable velocity or we could say launch velocity here and we'll default that to a vector 2.0 so when we pass in the launch velocity we'll set that so launch velocity equals velocity we also have moved duration which will be a float was default that to zero and then we'll say variable uh time since launch which will also make a float and default to zero and then we'll say variable launching as a Boolean default that to false so when we launched the pickup we'll say time since launch equals zero because we're restarting it uh the launching is going to be equal to true and the launch velocity set here I guess we also need to set the move duration up there I'll rename this to be duration and then move duration equals duration just having different names so it's clear that this is the member variable up here and then this is the parameter okay um next for function process we're going to check if launching so if the pickup is currently launching then we're going to move it so we'll say that the position is going to add in the launch velocity times the Delta which is the time between frames and then we're going to add in times since launch plus equals the delta and if time since launch is greater than or equal to the move duration then we're going to stop the launching so launching equals false so that will handle the movement what we also want to do is uh when the uh when that pickup is launching we want to disable the Collision shape so let's actually add a Setter there for the launching so set is launching so launching equals is launching and then we'll say collisionshape dot enabled is going to be equal to whatever the launching value is so if we set launching and launching is true then the Collision shape is disabled but if we set it to false then the Collision shape is going to be disabled now let's go back into resource node and we need to calculate the speed and the direction that we want to spawn this pickup in so that means that the harvesting node at the top we're going to need to set a launch speed for the pickup so let's export VAR launch speed and that'll be a float we can default this to something like um a hundred pixels per second I guess and we'll also have to do a launch time so export VAR launch time and we'll call this something like a float and 0.25 seconds that'll mean it'll travel for a fourth of a second at 100 pixels per second and then we'll generate the direction down here in order to get the direction we need to do if I Direction which is going to be a vector 2 and we're going to set that equal to a new Vector so it's a vector two then we need an X and A Y value so for the x value we're going to randomly generate between two floats and that's going to be negative 1.0 and 1.0 positive then we're going to do the same thing with the Y value Rand F underscore range negative 1.0 to 1.0 so basically it's going to generate a random Direction and that can be anything from left up down and right and everything in between so effectively it's going to create like a circle and then our Vector is going to point somewhere along that Circle so it could basically go 360 degrees now to make sure that when we get these values that it's just going to be a pure Direction with a magnitude of one we want to normalize this Vector with DOT normalized after we create it so that gives us our normalized Direction and we need to launch the pickup now so pick up instance dot launch as the function and we're going to pass in the velocity which is Direction times uh launch speed up here at the top launched speed and then we give it the time which is the launch time or launch duration let's rename it launch duration so that's our two parameters and now the pickup instance can launch let's hit play and let's see how that works if it works at all so I'll come down here and we hit the rock or a node boom so we get a problem here which is that the disable on the Collision shape is not something we can actually set supposedly let's see uh Collision shape then we have the disabled property ah okay so we want disabled as the name of that property not disable now we can save it run it again let's go back to the or we hit it okay and then we actually get it to spawn with our launch it moves at a direction for a set time and then it stops and then supposedly it also re-enables it so let's hit this one and you can see the Direction's randomized so we can do that a few times let's also take the tall VOC resource node and let's change the starting resources and let's make it three or you know what let's even make it five so that means it's going to take five hits generate five pickups before it goes away so let's hit play and let's Harvest this note so okay that one didn't quite work um let's see starting resources five let's check the game level if we click on these okay they all have the starting resources of five let's look at the script see what's going on here so current resources is going to be equal to starting resources which should be set to 5 here let's hit play one more time I'm going to look at the remote scene let's click on the resource things here we can see the current resources is actually zero um so I guess current resources isn't being set on load interesting let's add a breakpoint here to this line and we'll hit play and see what's actually going on so um we come in here the current resources is going to be set to the starting resources uh I see what's going on so when we run the setter function here for current resources we never actually set the field value so current resources equals the value we pass in or um instead of just calling it value we could say resource counts okay so I'll copy that paste that there and paste that there as well now we can hit save we won't need this breakpoint anymore hit play and now that should be working let's go down here we hit the rock okay we got one let's hit it again two three four five okay so you see we harvested five nodes here now these pickups actually are um static bodies I really should have made them area 2DS because you can see that as a static body they interact with physics we don't want them to interact with physics we just want to be able to pick them up so I have to change that but yeah all of our resource nodes we can Harvest them five times here and uh this one five times as well okay so that is pretty much working now we have 15 pickups and we need to be able to add them to the inventory Let's uh exit out of the game let's go into the 2D scene for the pickup Rock okay in the script here for pickup we're going to want to retype this to area 2D and we're going to retype the pickup Rock in the scene to area 2D as well so change type with right click change type area 2D now a area 2D we can look for an interaction but it's not going to affect the physics but we still should be able to move it with script like this let's test that by hitting play I'll run in here so we get our pickups and they are in the scene but we can walk over them which is what we would expect actually okay so let's hit close um now I did notice that the pickups they still have the Sorting going on so inside of the ordering uh for now I'm going to just change this to be something like negative five so if something like the player has a value of zero it's just going to hide behind it at all times so let's hit play and let's test that out here again so this will just basically force uh the pickups to hide behind the player by default so for our pickup uh we can have it monitor to see when a body enters it and if that body has a inventory then we'll just add the pickup to the inventory and we will remove the pickup from the scene so uh first off let's go to player that's called a node here for the inventory I will right click add a child node and let's make it a new node I'll rename this to be inventory and now let's create a script for inventories so for the inventory let's add a new script here we can leave it in character slash inventory.gd I suppose create and let's give it a class name class name inventory in the inventory uh let's create a dictionary for resources so it will include which type of resources are in the player's inventory and how many of those resources are in the inventory for each type so in our inventory we can create a dictionary for resources that we want to track something like export VAR resources and this would be a dictionary and we set it to equals this thing equals curly braces means a dictionary here so our dictionary will contain Keys which will be the resource that is in the resources dictionary and then the values which will be how many are in there so let's go back to pickup Rock and we can see that in the nodes we can do body entered body node 2D so basically in our script we want to connect to the area 2D itself instead of connecting it right here just to make sure it always works for any pickups we create let's actually just set that up in code so if we have let's say a function ready so function underscore already here and then we're going to connect to itself so let's do body entered and the callable is going to be on body entered yep let's just do that and then down here at the bottom we'll make that function underscore on body entered then we have the body node which is a node 2D let's pass and then I want to add the underscore back up here at the top okay so uh basically when the script starts we're connecting to its own signal and then we can come down here we'll check that if the body that entered the pickup has a inventory then we're going to add the pickup to the inventory and we're going to remove the pickup from the scene so let's do Vara inventory equals body dot binds child in the fine child the pattern we're looking for is that it is from the inventory class so um you can use a string for I think the node name but this will also work with class types so let's check inventory dot GD so class name inventory should match here so basically a node that has a inventory script attached should be found by this body dot find child inventory so if the inventory is valid we're going to do inventory dot add resources so let's say resource type and we'll write that up at the top and then the amount which is going to be one so up at the top let's add in export bar resource type and that will just be a type of resource we can come up here and be more specific later on maybe make it like build materials instead of just resources but it should work fine for now so now our inventory needs to add resources function so an inventory let's create function add resources so we need a type which is going to be a resource and we need a amount which is going to be an integer so when we add resources we're going to find the key in the dictionary if it exists and if not we're going to add the key to the dictionary and then we're going to set the amount of the resource inside of it so we're going to do resources of type and we're going to set that equal to whatever the current value is so resources.type and we're going to add the amount okay now back in pickup once we add the resources we can queue free on the pickup so after adding the pickup to the inventory we need to queue it free from the scene so let's remove it with Q3 let's go ahead and test now and see if all that actually works so let's hit play I'm going to look at the remote scene let's expand the game level the player and look at the inventory here so in the inspector over on the right we can see the resources the dictionary here now let's look at our game view so I'm going to harvest this resource let's go pick it up okay so it almost worked we got to the ad resources so invalid get index null the type is null um right so we need to actually pass in a resource type to that so that would be coming from Pickups here so the resource type is something we actually didn't set on the resource so that makes a lot of sense let's click on resource and we'll need to set a resource type here so for the resource type let's go into the items folder and I'll right click and create a new resources folder inside of here so these are item resources because they exist inside of the inventory let's right click here create a new script and this is going to inherit from resources and we can call the resource script something like resource item and in here it's from resource not from resources so resource item um or item resource whatever makes more sense to you let's create that okay so now we have this inside of the folder let's give it some Fields such as export VAR display name which is going to be a string we can give it a texture as a texture 2D as well so that if we need to display it in an inventory or something we know what to show for it and aside from that we'll just hit Ctrl s and save it oh wait we do need to give it a class name so class name is going to be resource item yep okay that makes sense to me now let's create a actual resource from that script so let's right click in resources item resources that is go to new resource look for item resource or resource item click double click on it to create it and then we're going to call this a rock item or resource rock yeah I guess I guess that makes sense okay let's save that there and now we can double click on it we can give it the display name Rock we'll give it the same resources texture that we use to show it in the game so rock item so if it exists in the inventory it'll actually show up with the same image and now let's assign resource rock.toes to pickup Rock so if we drag this into here now we have the item resource type associated with the pickup which is the object that exists in the game so we pick up a copy of the actual resource not the pickup Rock node itself so let's save that and yeah okay let's test things out again let's hit play Let's go pick up a resource let's walk into it okay so we have the resource now invalid get index on dictionary so I'm guessing it's this part right here trying to look up a value that doesn't exist so let's add a if statement up here so do if resources dot has and we'll look for a type and I think that's looking for the key then we'll do this as before okay so let's save that else uh what we'll do is we'll say resources at type is going to be equal to the amount because we're assuming that this it hasn't been set yet so the amount is zero let's give that a shot I'll add a break point for both of these and we'll see what happens I'll hit play uh let's go down here let's get it get the resource okay so of course it didn't have the type so we're going to try to add it now I'll give it at the breakpoint let's hit continue okay execution resumed so let's take a look at our remote scene the game level player inventory so we can see in the dictionary that we have a size of one now and so when we added it I believe this should be the resource here and then this should be the count so uh let's continue let's get another pickup so we get it and let's continue control's got a little screw there um but let's go click on the inventory and let's see if it was able to add another copy of it uh to the inventory so we expand the dictionary and now we have two of the items so the only thing is that the item is kind of showing up a little weird here let's uh close the game there for a second for the type I'm going to actually rename this to be resource item and let's add resources yeah add resources yeah okay sure that's fine still I wonder if this changes anything so uh let's go gather a couple resources and see how that shows now okay so we got our resources remote uh game level player inventory let's look at the dictionary and it's still showing up okay so now if we go ahead and we collect some of these pickup items like so let's go check the inventory by going to ziggado engine remote view game level player and we look at inventory and we'll see that we're picking up the resources now because our dictionary has items you can see that the resources being stored here as a object it's a little hard to tell exactly what this is looking at the inspector view but we can see that we picked up two of that item so seeing the objects here is a lot easier when you would be looking at let's say the debugger view so if we let's say look at the inventory script and we have the bit here where we're adding something to the inventory let's add the debugger point at that point and let's go collect another resource okay so now it's going to stop at that breakpoint and we can see the object here represented outside of the dictionary so you can just click on the object and you can see what type it is here rock with a texture side of the Box looking at the dictionary might not be the most convenient way of seeing how many objects you have of which type so what we could actually do is create a in-game UI so that we could see how many of each resource we have picked up so let's go ahead and exit out of the game now and we will do that so let's go up to scene new scene and do a user interface so we have the control node here I'm going to change the type of bit to something a little bit more useful let's right click and change type so let's expand the control nodes go into container and find a container that would be useful for showing a whole bunch of icons with how much we have in the inventory so I think we'd be looking for something like a grid container we can try that so let's change it to a grid container for columns we can just decide how many items we want to go across before we jump down to a new row so I'll say something like 5 for now is fine we can rename this to be resource display okay and now let's control s save this in our project so I'll create a folder for UI and we can just call it resourcedisplay.tsu so in our resource display we're going to want a little side by side with a label showing a number and then something like a Sprite showing the texture of the resource so that we know how much of that resource we have we could also add in the name of the resource um optional if we want that so I'm going to right click here and do add child node and let's go into control so we'll need another sub container for that let's go to container and then we can do box container and horizontal box container so this will make each item go horizontal I believe let's try that and then under this we'll right click add a child node so let's get a label for the number and I'll right click on each box container again and let's see what we can use for showing an image so under control we have texture vect I believe that's what we want so let's create that I'm going to re-parent the text direct to be above the label so the image comes first and then let's create a little sample here so that we can see how it will look in the actual thing so let's go to Art gathers exterior resources and let's just let's grab something like coin copper here I'll drag that in okay so we can see that this is stretching the icon in a way we don't want let's go to stretch mode scale and do keep aspect okay that looks a little better and now let's go to the label and put 0 for the number let's rename the hbox container to be let's say resource item display I guess okay and if we duplicate this a few times then you'll see roughly how the UI would start to look if we zoom out all the way then we'd have this little UI in the top left hand corner and it would be going to the right now of course we can see that our icons are too small I'm going to delete a resource item display two and three don't need those right now so next let's go to the text direct and let's fix the sizing of our little icon here I'm going to go to expand mode and let's try fit height proportional or no fit height and then let's do fit with we could try fit with proportional okay that looks good and then we have the number over here so we'll need to kind of make this bigger than it is right now okay so we can check how big it's going to look in game now by running the current scene remember that in our window settings the scale is increased by four times or so so that's why it appears so big here compared to here now we probably don't want these grid items to show at the very top left corner so maybe we can add a margin around our grid box let's go to the resource display I'll right click add a child node let's look for margin container okay and then drag resource item display under the margin container and in our margin container let's go to let's see theme overrides constants and let's set some margins here for all four directions and let's try ten ten ten ten so with that now our actual grid items are inside of this larger container if we run the scene it's going to I mean it's kind of big but um that'll be a lot better at least so now we're going to need a couple scripts one for the resource item display so that when we set a resource and a value here that those will be updated to the texture and the number here and then one for the resource display where we'll have it listen to The Player's inventory and whenever the values change in the inventory about how many resources the character has then we're going to update the display so let's right click on resource item display and do a new script so we can attach a script and we'll save this under a UI resource item display.gd okay let's save that there so I'll get rid of this stuff down here and what we're actually going to want here is going to be a class name so-called resource item display then down here we'll have our resource type which uh we'll have to get the item type so let's see items resources we were calling it resource item so if we do yeah resource item here then that'll be good by default it's nothing we'll also need a couple on ready vars so on ready for of type text direct equals dollar sign text Direct and then we'll need the label on ready for label typed label equals dollar sign label we could also create a simple function down here function update count and this will take a count as an integer and then we take the label.txt and we set that equal to the count we might need to make that a string so let's do Str of count not sure if that's actually required or not but just in case all right so that'll update the label there and now we need to create a script for the resource display so let's add attach a script to Resource display so the first thing we can have here is going to be a list of resource item displays so that will be a of a so far resource item displays or you could just call it um displays actually and that'll be of type resource item display equals an array of resource item display so what we'll do with this is that whenever the player inventory adds a new type of resource will create a new resource item display so for that we need the template which is what we created already and then we'll create a new copy of that under the margin container so let's add an export for for item display template which is going to be of type no not resource item display actually is a packed scene because it's from the project uh now we can click on resource item display and where you can set the item display template so we have to save our resource item display to the project so I'll right click here Save branch as seen under UI and we'll just save this here okay now we can remove the resource item display from our scene because we don't want it to be there by default and instead on resource display let's go to the UI folder and let's grab the resource item display and just drag that in there so we have the template and we'll create an instance under the margin container whenever we have a new type of resource we don't need radium process functions so let's get rid of that we are going to need the margin container so at on ready VAR and maybe I'll call it something like display container inside of here which is going to be of a type margin container and we're going to look for a dollar sign um we'll rename it to be display container so let's make sure that's the name of our merging container so I'll rename it in the scene view to display container so we want to connect our resource display to the player's inventory so we can look through the game level scene if we wanted to look through all the nodes and find a inventory node which would mean a lot of redundant looking at other nodes in the scene that don't really have anything to do with our player or what we can do is give the player nodes a group which is like a tag and then we can search the nodes that have that tag player and only look at those nodes instead of looking at every node that's active in the scene so to do that we would go to the player node and the player scene in our project let's go over to the node Tab and instead of signals choose groups and give it the group Player so now we can search this node just by looking for the tag player let's go to Resource display inside of here it will have a function underscore ready and first let's find the player so the player is going to be of type player controller but we haven't actually given the player script that uh class name so let's give it class name and we could just call it player actually that's more consistent with the name of the script so class name player now let's go over to Resource display so we're looking for a node that is of type player and to find that let's get the currently active tree so that would be like the level or the main uh scene for the game and we're going to look for a group so if we look at groups we can do get nodes in group or we could get first node in group so I'm writing this to be a single player game and we would only expect it to be one player so for that case we'll just get the first node in the group the group name is player so we're going to get that player node there so then we need to get access to the inventory and we'll actually make that a member variable so up here VAR player inventory which is going to be of type inventory to find that player inventory we need to search the player node so player inventory is going to be equal to player dot find child and the pattern we're looking for is inventory as a class name and that should be as a inventory this part's probably unnecessary but it doesn't hurt with being very specific we're looking for that inventory script and we're setting it up there okay then what we need to do is connect to the player inventory signal but currently there's no signal for inventory so let's go to the inventory script and create one so in the inventory script uh let's write a signal so to do that we can do if our signal resource count changed and that is going to mean that we need the type in the new amount so type resource item and then the amount is new count which is going to be of type integer so after we add resources we want to emit that signal so we can come down here below the if else and write emit signal so the signal we are emitting is of course resource count changed and then we pass in the parameters so the type is type and the count is the new amount so that would be resources type which is going to give the value associated with the key there now that we have the signal emitting go back to Resource display and we can connect to that signal so player inventory dot connect so we're connecting to whatever that signal was just called resource count changed so just paste that in there and then we need to give the Callback method so we're going to have a function in here called on player inventory resource counts changed okay and now we just have to write that function so add a couple new lines and then function let's just copy and paste this name it's kind of long so on player inventory resource count changed and that's going to take the same parameters so we have the type of resource item and then we have the new counts which is an integer and I guess uh this is going to be turned void so we can specify that as well okay next let's make sure there's no errors okay great so let's um let's change this pass and write a print so new count for and let's do type dot display name is going to be is and then well we need to convert this integer into a string so string new count so as long as this resource display is active in the scene we should be able to get this callback to run so let's go to the game level and we can add it in here maybe later we would uh have like a main scene load the level and it would only have the resource display load once not every time we load the level but for right now let's just for the sake of Simplicity we'll add the resource display straight to the game level so let's right click in here and add a child node so we want a canvas layer usually you want this as the base for when you're adding UI controls to the scene it'll keep the UI positioned in its place no matter where the camera is moving around in the scene so if your UI is in the top left it'll always stay in the top left no matter where the player in the camera goes so canvas layer and then let's add in our resource display just drag and drop an instance of the scene and then position it under canvas layer um yep and okay and now that we have that active in the project let's hit play and let's see if we can get that call back to occur okay so first off in the scene displays resource item display is an array of resource item display all right so what's going on here is that this should be the type not assigned so we're going to put array resource item display over there and get rid of the equal sign um so by default that's just going to be a empty array yep okay now let's hit play and run that again okay so scene runs let's see if we get the Callback print messages when we pick up an item so I'm going to come here okay we have new count for VOC is one so our UI is now responding to when we pick up items so it knows what type and how many so that's very good that's what we need to start adding to the resource display UI so we already have the display item template first we want to check in our array if a template that supports the specific type already exists and then add the new count into that and if there isn't one for that type coming in then we create a new instance of the resource item display and reset the type to the new type so first uh we'll find existing item display for type if none exist create a new one okay so to find it we have to do a bar so far current display which is a type resource item display so then we need to Loop through the array so for display in displays if the display dot let's see resource type I think that's what we want did I really make that a capital though so let's go back and check that script resource item display let's open the scene let's look at this script yeah I did actually so let's make that resource underscore type be more specific um you know just standard naming conventions and let's go back here and do display dot resource type is equal to type so if that's the case then we've already found the current display so current display equals uh this display and we can break so once we find the correct display we no longer need to continue through the for Loop so then we're going to check if the current display was never found so if current display is null then we're going to create a new display so we want to instantiate under the display container a new instance of this item display so we're going to take let's see I item display template so far new new display equals item display template dot instantiate okay and then we need to set the parent to the display container so display container dot ADD child new display okay and yeah I think the display container will take care of positioning it so we just need to set the new values into that okay so the new values is going to be we set the resource type so let's actually specify this as a resource item display so that we can see what member variables it has and then we're going to instantiate as a resource item display okay okay and now we can do new display dot resource type equals type and then we'll say new display dot I think I add a function update count yep update count and we're going to pass in the new account okay great so we just need to do the same thing up here if we have a current display so we'll do current display.update count new count so here we create a new display and we set the resource type and update the count and then here we find the display based on the V Source type and then we just update the count so here we can say find existing display and update the account if one is found okay so hopefully that's not too complicated there let's hit play and test it out so we're going to go gather a resource and then boom and then okay we have our display added to the top left hand corner um the only thing that's a little weird here is that the margin did not seem to work and I think I may have seen why that could be so if we look at the game level and we look at our resource display uh we'll see that the margin is actually going outside the bounds of our screen by the looks of it so let's jump into here take a look at the resource display we got theme overrides we got the display container it could be that this should be negative no that's not right okay I guess we can um hit play and we'll take a look at the remote views up here in the game level so we take a look at the resource display but we got to look at remote so let's see canvas layer remote display display container and we have our resource item displays under here okay that's kind of interesting though we have two set here all right so that's definitely a bug we get a new one added every single time yeah okay I think I forgot to add it to the array so let's do that part first so when we create a new display we need to add it to the existing displays array so displays Dot append and we're going to append the new display okay that way when we search through the array the new display will show up so it should only create it once that's it play let's gather our stuff yeah now that's working okay so to fix the positioning on the resource display let's go to Resource display here and try making the anchors preset full effect okay so that should make it the full UI view of whatever we attach it to so if you go to game layer okay that's actually kind of like what we just had let's see let's check the layout transform oh position negative 10 negative 10. okay that might be our problem here so I'm going to reset that ah okay okay now now the position is correctly in the top left so let's hit play and we'll see if it actually positions things correctly okay good it is it is that's nice so now to demo that this will work with other types of resources let's just create a word resource and put one randomly on the map for us to pick up okay so under items resources let's create a new uh let's create a new resource so we're looking for item resource resource item this will be resourceward dot Tres so we just need a name and a texture so this is going to be and then the texture let's go up to resources and we'll do wood Brown so maybe we rename this to be brown Ward you could call it whatever you want really okay and now we need a pickup object associated with that so I'm going to duplicate this pickup rock as pickup ground wart let's double click into here let's change the resource type here to Resource wood and by the way if you don't like how it shows the file name like here in um resource rock you can set a name here rock you could go into Resource Board and you could set round board here as well so then when we look at our scene and it references it in the inspector you'll see it referenced by name here instead so you can sew over it and see it's resourceboard.tres let's rename the pickup to be pick up wood and then we need to change the texture to be our wood textures just put that there and let's change the size of our Collision to actually match our Uh Wood so something like that is pretty good now let's put a couple inside of the scene so first I'm gonna um first let's close a few of these tabs okay and now let's go to the game level and let's drop some of these pickups in so pick up round word pick up brown Ward I pick a brown wood so now we have some extra pickups in the scene let's hit play now notice because we didn't run the launch method on these pickups that they just exist in the scene they're not moving or anything so let's go get this one okay and uh I guess I didn't set a texture there so I guess we still haven't set the texture here but we should be able to get two to appear so let's get two and we did get a second to appear in our grid but it's not showing quite properly but you can see how the first one had a one and now a two and the second one at five so at least it knows that the types are separate uh let's work on setting the texture so in uh resource item display let's jump into the script we can just have a Setter that whenever we set this resource type we're also going to change the text direct texture so let's make a Setter function here so set new type and that's going to mean resource type is equal to the new type of course but we also want to update the text direct dot texture is going to be equal to resource type dot texture okay now if we hit play it should correctly display which item is which up here okay and now we'll get the Rock and well The Rock's pretty big over there but um yeah it's definitely showing the right texture at least now we just need to get the grid layout to work so let's take a look at our resource display scene and 2D View kind of zoom in here and let's try dropping two items under display container so resource item display and resource item display okay so we can see they stack on top of each other here uh really I guess what we need to do is that the resource display should be under the margin container so let's make it so that the display container is actually the root scene so right click make scene root and let's bring these two under the resources display okay so that lays things out correctly now we can rename this to be grid and we'll rename this to be resources display or a resource display actually and then we're going to attach our resource display script to this node we're going to remove it from the grid node so let's remove it there and then we just need to make it in the script so that we're taking this grid instead of the display container as a margin container and we're going to add it to the grid so grid is going to be a grid container we're looking for a dollar sign grid oh we could just make it grid container actually and we'll rename it grid container as well in the scene view okay so now we I'll give it container we just need to add the child to that instead okay now let's go to play Let's collect our resources uh oh yeah yeah of course so we have to change what this extends which is margin container okay now let's hit play let's go collect our resources instantiate unknown value oh great because we changed the way the script is we need to set this up again so take the scene resource item display and put that in the slot here um in 2D view also remove the test resource item displays okay now finally we can go to play mode and we can pick up our items so there's our first and there's our second Okay cool so we are collecting different types of resources here uh they're kind of big on the screen but you can see how we can easily keep track of what resources we have now in your actual game maybe you'd put this in an inventory or something so you couldn't always see it or we just shrink it down to the top left of the corner I don't know if you want this to be more like an RTS or more like an RPG um but let's actually try to make that a lot smaller okay so first off the resource display uh let's take the margin and make that five since it's being Amplified by four scale um it's really like 20 pixels when it's five and then let's make it so that each item is smaller um I'll add a couple test items back in here so that we can see what their size is and then we're going to work on resizing those to be smaller let's start with the resource display size and I'll make that let's say 26. so I want to take our resource item displays for the text direct I'm going to shrink that back down to keep size so we'll just show the actual size of the Sprite and then we're going to need these uh labels to be much smaller as well so on font size fit theme overrides I might take that or write it to something like eight okay so I'm not really sure why the text down here kind of floats into the middle with this hbox container I'm actually going to try uh changing the resource item display to a different type let's try changing it to a little container it's a horizontal flow container yeah let's try that okay so that makes the text come up here and um I kind of want to shrink that if I can so let's resize this yep um we can try something like that now let's go into the script and just make sure that we are using this type which I think was horizontal flow container let's just change the script resource type so next we'd like our texture to be centered with the text as well centered vertically that is so let's see if we can get that in layout so if we do stretch mode maybe we can do keep aspect centered okay that actually seems like it's good keep Center to keep aspect centered let's say that keep aspect centered let's say play okay we see our items up there we got our new resource we added in and we can collect those resources so that's looking pretty good uh not perfect but it definitely works right now okay now we can go to Resource display let's get rid of these default dummies and save the scene okay so now let's go hit Play One More Time collect the resources and we can see that now that we have this display in the top left hand corner it's pretty obvious how much of each resource we have as we pick them up so it would be pretty useful indicator you could also move this same thing into a pop-up window like an inventory when you press a key like I or something if you'd rather it show up there rather than on the screen at all times uh but that's pretty good for showing our collected resources so next I think it would be a good idea if we created an actual game level for the character to run around in so to do that we'll need a tile set and we'll need to set up some Physics collisions to those tiles so in the game level scene let's right click on game level add a child node I'm going to look for a tile map so add that and then the tile map is going to need tiles so to get tiles let's go to the art pack go down to tile sets and then we can use some of the tiles here so let's start with tile set grass I'll just drag that in here so our tile map so our tile map is going to need a tile set in order to have tiles to draw onto the tile map so let's create a tile set in the top right in the inspector with tile map selected so go to tile set empty do drop down do tile set and then for this we're going to left click and do it now we have this window for tiles so if you go into art gatherers exterior tile sets we can come down here and bring in some tiles so I'll start with tile set grass drag and drop that here and we can automatically create tiles in the atlas from this tile set image so we'll hit yes and you can see that it separates all of the tiles to 16 by 16 tiles which is what we expect for this so to draw with these tiles we want to click on tile map at the bottom click on the tile you want use the paint tool and then start drawing onto the tile map so you can just kind of draw and the tiles will go into their space you can see in the tile map on the far right the tile size here is set up 16 by 16. so you want to have this set to whatever size tiles you're drawing so that they line up in the level correctly now right now these tiles don't have any Collision added to them let's start by using this rectangle fill tool and I'm going to fill in this green tile something like this and then let's draw the edge tiles as well so I'll use this one in line mode to go from here all the way up to here the other side on the right up to here this one at the bottom from here to here and then these Edge tiles something like that and then at the top we'll have this corner we use this one to go the middle section and then the top right hand corner okay so then we kind of have our little island tile set up uh now to add physics collisions to this tile map and the tile map inspector you go to physics layers add a new physics layer and in this physics layer we can see the Collision layer which is where the collisions are going to exist when we set them up inside of this tile set editor so basically anything checking for collisions on layer one can be blocked by these tiles so go to tile set now and we want to paint a property of the physics layer 0. so when we add in the collisions we're adding it by adding a collision shape on physics layer zero so let's start with these bottom tiles here I'll left click on them so by default it's going to just create a box around the full shape size but you can click on the corners and pull them up like this if you don't want the Collision shape to actually be the full tile size which in this case makes sense because these tiles are only half tiles and then you have theoretically the water beneath it so make it something like this right here and then to take this same and then to take the same Collision shape and copy it over to these tiles just left click on them and then left click here and then we'll just keep taking the template you just created and applying it elsewhere so now if I was to hit Ctrl s and hit play we can walk down here to the ground here and these tiles are actually going to block out characters movement now everything else does not as you can see and also our tile map needs to be definitely behind the player in terms of sorting so to make sure it sorts on bottom you can click on tile map go to ordering and make the Z index something like negative 50. okay now everything else in the scene shows on top of the tile map so that that's more correct so now for the rest of these edges you could either create a razor thin physics Collision where we have these black edges or you could consider um just adding water tiles and then the water tiles have a physics Collision but then if that would be the kit or you could consider adding water tiles which would be unwalkable but that could cause a problem too because if you have something like a bridge or boat then those could be affected by the physics Collision as well so the next thing we're going to want to do here is to add in probably the water tile set so really in this pack that's just one single tile so let's go into tile sets and look for tile set water and then we can drag and drop it into this tiles area or actually you do that on the tile set tab so drag it into tiles but in tile set automatically create the tiles then let's select this tile and we will give it the Collision shape so you can hit F to do the default Collision shape and then left click on the tile to make sure that it gets added in so without tile map we'll also create a separate layer for the water tiles to set on one reason for doing that is that ground tiles like this one might not have the entire tile filled in so you would want to have some water under it in the background and that would be possible if you use multiple layers so let's call the first layer layer ground that's what we already Drew on and then add an element and we'll call this one water so to draw on the water layer click on this drop down menu go to water and now you'll see that all the ground tiles kind of Fade Into the background meaning that those exist on a different layer than the one we're working on right now now I also want to take any water tiles and have them behind our ground since those would sit late since those are sitting under it so for the Z index on the water layer I'm going to set that to negative 50 so that it's automatically below everything else here so then I'm going to select the water tile so in this case I don't want to put water under anywhere where there is ground because because that will end up causing collisions even though the ground tile doesn't have Collision the water tile does so in this setup I'm just going to be careful to go around the land and not draw inside of it so let's click here for a erect shape and then let's drag in some water tiles so just draw in the shape then we can also go up here draw on the shape and really you can make it as big as you need to so if you want to have a large tile map just feel free to drag in a whole bunch of tiles okay let's also create another area over here for a another Island that our character will eventually be able to walk over to so I'm going to delete and cut out some water tiles just whatever I want the shape of the island to be can make it something like that sure and now let's switch over to the ground tile and click on tile set grass so we'll start by filling in this whole area with the grass tile so use the vector tool and make sure you turn off the eraser so let's drag in the grass over here here and here now we just need to fill in the correct tiles that surround that so down here should be this one then we can drag like this put that there and here here just kind of filling in the edge tiles so let's do that okay now we need the left side so we'll fill in this and if you wanted to it's possible in Godot to create auto tile rules I don't think I'm going to be covering that in this video just for simplicity's sake so we're just kind of going around the border and doing this manually for right now so lastly we do need to add water tiles here and I guess that's already there but let's go to water and then draw in water tiles at this bottom line and that should pretty much be good for right now so let's go ahead and hit play and make sure that it is working with the collisions so we come over here and the water blocks us as well as the bottom of this ground down here so next we need to figure out how we're going to build a bridge between these two areas so let's open up the tile set again and I'm going to drag in this tile set Floating Bridge to this area and we'll automatically create tiles for that now these tiles are going to go on a top layer so I'm going to once again go to the tile map add an element and we'll call this uh top layer let's leave the Z index at zero and I'll take the ground and make it negative five for right now okay and then let's uh use the tiles here to put a bridge across the water so let's switch to the top layer use the pencil tool or the paint tool click on the tile we want put it down and then add in the bridge area and the final piece over there now right now even though visually it looks like we'd be able to just walk across this bridge the reality is that the water under it is causing a collision to occur so we wouldn't actually be able to walk across it now there's probably a good handful of solutions to this but in this case I'm going to do the simplest one possible which is just going to be that we'll have a separate water layer where whenever we put a bridge in our game we'll just make the water under it not have a collision shape since we don't need the water for anything else really other than visuals and causing collisions so to do that we're going to go to water I'm going to right click on the base tile and create an alternative tile on this alternative tile we're going to have no Collision shape so we just use this alternative tile and in tile map paint mode and then we're going to add these no Collision tiles on the water layer so just like this making sure that all of those tiles have no Collision so now we should be able to hit play and actually walk across the bridge so let's go over here and we can walk this way you can see that now the water is allowing us to cross really the bridge itself doesn't do anything other than a visual it's just the lack of a collision shape that's allowing us to cross the bridge okay so now we can hit play and test this out so we'll walk over here the water and all the places still blocks us but if we go to this area with the alternative water tiles and the bridge we can walk right across it so now we can access the second island which is pretty cool next let's create a second harvestable node uh which will be a tree and we'll make it so that you can only Harvest it if the player is equipping a ax instead of a pickaxe so let's go into our objects folder where we have the resource nodes and I'm going to start by duplicating the resource node Rock tall and let's call this a resource node tree so we'll double click into it and of course the first thing we're going to want to do is change the Sprite so in the art pack we'll go to the objects and we'll find where we have a tree we can use so I guess we'll use this pine tree let's drag that in there and we can also rename the scene file to be pine tree as well or let's do tree underscore Pine to have it sort better alphabetically let's rename the node in the scene resource node fine tree and the pickup type well we already created that it's going to be brown Wards so drag pick up brown board into the pickup type scene we'll leave most of the other settings alone here the last thing we need is to change the node type so this is going to be for nodes that are harvestable by ax so we need to create that type and resources types so let's create a new node type I'll right click new resource I'll search for let's search for type and then we have resource node type.gd let's create that and we can call the resource type basically whatever we want uh since the first one was called minable I'll just call this one axible I don't know if that's even really a word uh but it just refers to something that can be harvested with an ax so let's save that type and click on the resource node and then let's drag in axible to replace minable.tres so now we know that this is a resource that will be harvested by a ax so next we need to set up the tool and I think we have that in items folder so we have the copperpickax.tres let's uh duplicate that with Ctrl D and I'll do copper ax.tres so double click on copper X or TRS and we'll have the affected types here so we need to switch to the other affected type of axible so next we need to switch the affected types here to axible as we were just talking about so let's load and we'll go into uh objects resources types and then axible okay and we need to change the name here from copper pickaxe to Copper X and the texture of course we'll use the ax icon for that so in tools we have ax copper let's drag that in there and now we have our second type of node and the way to harvest it let's add some trees to the game level obviously the file system has a lot of items now so we could just filter by typing in resource underscore node if you want to quickly find the tree so I'm going to drag this into the scene like so we can put a few of these trees in which will be harvestable with a ax so just whatever you think is good for them one thing I do want to change though is the position of this Collision shape I'll move it down a little bit inside of the resource node pine tree scene so open that up Collision shape let's just uh W to move it and move it down to the base of the tree I might shrink it a bit too so something like that will do pretty good so for sure these pine trees are harvestable nodes but let's show that it's not going to work with the pickaxe because pickaxe's only target minable nodes so let's go over here to this node and you can see the wood trees they don't do anything right now but we can still harvest the box of course we can still pick up a tree that's on the ground or a wood that's on the ground but we have to be able to switch to a copper ax now if we want to actually Harvest a tree so the next thing we're going to want to add is going to be something like a hot bar where we can switch our different items out by pressing on buttons that will appear at the bottom of the screen so I'm going to right click on the canvas layer this is where we'll just set up all the UI stuff and we'll add a child node so let's start a new scene with file new scene go to user interface and we will set up our hot bar at the bottom of the screen so we can right click on the control node add a child node and let's try a grid container again so this grid container I wanted to show at the bottom middle so let's go to layout and change layout mode from position to Anchors and anchors preset to bottom middle I think is what we want let's see Center bottom so that's where our buttons are going to show up now so we can right click add a child node so here we can try with a button I'm not actually sure if we want texture button or button but let's try normal buttons first okay and we can set an icon here so let's actually add in the copper ax icon or copper X copper.png so we'll drag that in there and let's see so yeah okay that should just work with a normal button so we could duplicate this and add in let's say like a hammer button and duplicate that again and we'll add in a pickaxe button now we want these to lay out horizontally so let's click on grid container and make the columns 10 which means that until we have 10 buttons it's not going to jump to a new line and then we need to add a script where we can take the buttons and use it to equip a different item to the player based on which button we press let's also take the grid container first and take its size and I'll make it 20 pixels so I guess it goes to 24 as a minimum and then we can recenter it at the bottom so Center bottom I guess we'll just manually move it down here so as long as you get it to the bottom middle of the screen that should be good enough for right now okay I'm going to rename the control at the top we'll call this uh we'll call this top bar let's save the Hotbar scene into the UI folder then we'll attach a script to it hotbar.gd and here it's from control that's fine and we'll save that as well okay next I want to take each of these buttons and I want to rename them to be item buttons because they're going to have a item attached to them so let's have item button one item button two item button three and let's attach a script to the item button so if I click and attach a script extends from button and in these we're going to have a item that is set to the button when the button is pressed we'll be able to set that item uh to the player if it is a equippable item type so let's do export VAR item and I'm actually going to create another class which will just be item for the game uh since we already have equippable item.gd but not every item you put on a Hotbar would necessarily be equippable a lot of games would have consumable items like a healing potion or something so we can have a base class that all items build from all items that can be put on a Hotbar at least so let's right click on resources and I'll do new script this will extend from resource and we'll just do item.gd and let's make sure that is out in items folder so now equippable item is actually going to extend from item we can pull this information display name and texture out to item.gd so class name item and then I'll paste that in display name and texture because all items are going to have both of those and because when you extend a class you inherit all of its properties so a equippable item is going to have the display name and texture because it is a item so equippable item here extends item and then we don't need this because those are already defined now one thing I have noticed is that when you kind of restructure your classes like this that sometimes the inspector doesn't automatically update um for your classes and your exam and your existing resources so I'm just going to restart the editor so we can see how it displays here after it recognizes the item class so let's go to Project reload current project okay now extend items and go down to Copper pickaxe okay now you can see uh the fields are still there and they still have the same data but now this information is actually coming from item as a class not from equippable item so we can still actually write new Fields an equippable item if we need to and just note that now these fields are coming from the item class okay now what that allows us to do is go into the item button and and we'll have an export bar for the item in the slot here so this is an item and now it can take any type of item not just an equippable item and we're not going to need a ready or process function here let's make sure that all three of these item buttons have the same script or really let's take item button and right click and save it as a scene in our project in UI of course so we'll save that there now we can just take these two item buttons and now we'll duplicate the item button and now all three of these buttons are inheriting from the scene which is better because now we can jump into the scene to edit all three of them at the same time okay let's just quickly set up the textures again so under art let's get the tools so Hammer can be there and the third one of pickaxe is there but what we really want to be having here is a Setter function on our item where when we set that we also update the icon automatically and we can have that run in the editor using at tool annotation just like we did before so I'm going to jump into the item script let's go up here to the top I'm going to do at tool so now code is going to run into editor as well and let's create a Setter function so new item or we can call it item to slot that's going to be a type item obviously so when we set the item to slot we need to update the member field select that item equals item to slot okay I guess we can't actually Define that type there and there's really no need to because we know that when we're setting a value here it's already an item okay so what our button does have is a icon field so we need to set that icon field to whatever the texture is from the new item so icon on equals item dot texture okay and that is probably all we need right there let's test it out so an item button here let's go and get our items so we have copper pickaxe and we have copper ax so let's test with copper pickaxe here I'm going to drop this into the item slot oh yeah that's right for the tool script to actually work you have to reload the editor first so let's go to Project preload current project okay now we'll click on the button let's get the item copper pickaxe and drop it in there okay and you see the icon updates immediately so the second one we'll click over here we'll just drop copper ax here cool that's updating the icon as well and we'll create a copper hammer item as well to go along with that so duplicate copper X and I'm just going to call this copper hammer dot TRS so let's click on copper hammer and then we'll rename this copper hammer for the affected types right now it doesn't have any I'll just delete the affected types so the hammer can actually affect anything yet and the texture let's load from the project and art gathers exterior tools and we have copper hammer okay so now uh that we have that item as a resource we can drag this into the item slot and the copper hammer is now showing up there uh next we want to connect our hot bar to the player uh so that the Hotbar can access the currently equipped item on the player and change it when one of these item buttons are pressed so we set up a node group called player specifically for the player character so we can use that in order to find and access our node so let's jump into the Hotbar script so we're going to have up here at the top um at on readyvar player is as is of type player and we're going to get that equal to gitree dot get first node in group because there's only one player single player game and we're looking for the group Player and that should come back as a player node okay so when we have the uh player node then we can pretty easily get the hand equipped node as a child of the player which is where we put the equipped item so let's check on Valley if the player was actually found from onready and if that's the case then we can do up here of our hand equipped I guess we can give it a class name too so in hand equip I'm going to give it a class name and equip or no underscore hand equip now let's go back to the Hotbar script so our hand Equippers of type hand equip so if there's the player then we're going to get the hand equipped under the player so Hand equip equals player dot find child and we're looking for hand equipped so you can search by class name and you can also search by the name of the node so once we have the hand equipped we just need to know which item is being changed out on the player and then we can set it up so we don't need this process function here for sure the next one these item buttons are pressed we need to have the item that they are storing equipped to the player if the item is of a type equippable item so taking a look at the signals here the signal repressed doesn't actually specify uh which button was pressed which is a little annoying so I think as a workaround what we'll do is we'll have the Hop bar tell each of the buttons what the hand equipped that's active on the Hotbar is and then each of those buttons can respond to their own signal and we don't need to worry about which button was pressed because each button will respond to their own signal individually so uh we need to get access to those buttons so let's do at unready VAR grid com grid container which is of type grid container we're going to set that equal to grid container so if we get the hand equipped then we're going to get all of these buttons under the grid container so for button in let's see grid container dot gets children and then to easily see the field on those buttons and make sure that it's the right type of button let's go into the item button class and let's give this a class name as well so class name item button so now we can check down here if button is item button and then we can do button dot item because we've already confirmed which class it is so we have access to the fields obviously you would have access to them anyway it's just that they'll show up as a hint now that we're dealing with the class name so a button hand equip is equal to hand equipped so we'll need this field in the button as well so we'll go into here we'll have our hand equip of a type and equip of course and that's how we let each of the buttons know about the dependency hand equipped when our script starts so that they know where to put the item and they also have the item to put so now we just need to connect each of these buttons to their own signal one way we could do that is with function underscore ready and we'll just connect the Pressed signal to unpressed to a new function we're about to create on rest okay and uh just to be consistent with naming schemes underscore okay let's create that function Now function on pressed underscore on Crest so the first thing we're going to want to check is if the item is a equippable item so if item is equippable item then we also want to check if the hand equipped is valid if and equip does not equal no then we're going to take the hand equip and we're going to set the item that's equipped to the item so handy quip dot equipped item equals item and I renamed equippable item to have only one p so that should fix that up okay so our buttons will now respond to their own signals and we can put the item in the hand equipped slot the Hotbar will take care of finding the player and finding the hand equipped slot um reason to do it like this rather than on each button is you might have 10 buttons but just finding the player once and telling the different buttons about where the player is or where the hand equip is is just a bit more efficient way of doing things so let's go back to our game level scene 2D View and let's put the Hotbar under the canvas layer so hop bar and the file system drag the scene here okay we can see it down there and now our UI let's hit play and we have our Hotbar down here let's test it so I'll click here and we change our equipped item click here for the hammer here for the pickaxe and just like that we have a Hotbar which will work for switching out tools so if we switch to the pickaxe we can Harvest this node and get all that stone but if I switch to the Hammer you can see this tool doesn't actually work for that and neither does The X yet oh but the X might be able to harvest the tree now okay there we go yeah we're harvesting the tree got all of that wood and of course you'll notice here that when we're harvesting these trees we don't have to use the swing animation yet so we'll set that up in a minute so that you only Harvest during the swing animation but you can see how our different tools are now harvesting different nodes which is super cool and we can just switch between our Hotbar tools with just one button press so one last thing before we wrap up with our item button script here since we're using the at tool annotation in order to make it so that we can set the item texture in the editor whenever we update the item but adding add tool also means that other code may actually run in the editor as well now I'm not sure if at now I'm not totally sure if underscore ready or the Callback on press are going to trigger in the editor but we want to make sure that they don't I think so let's add the bit in to make sure that it will only run in the actual game despite us having the at tool annotation so if we do if engine dot is editor hint then that means that the code that follows is going to run in the editor so we want if not engine.is editor hint and then on the next line add the tab so we save that so this means basically any code that comes after here we're going to skip when we're in the editor but we are going to run in the game and we want to put the same thing down here on pressed so when you're using at tool although it's cool to be able to run code in the editor you do have to be careful when you're combining it with your actual in-game code so let's still make sure that the buttons still work so if we go in game we can see that they do but this should now prevent us from accidentally pressing on the button and setting the hand Equip to the player when we're just editing the game here because that could kind of mess things up and we don't want that to actually trigger so be careful with your ad tool and then use these lines when you want to separate your our editor code from your in-game code one more thing for this little hot bar let's move it off at the bottom of the screen by about 5-10 pixels kind of like we did up here so I'll close out here let's go into the Hotbar scene and let's um we could add a margin container which would work all right or we could just take the grid container and let's hit W to go into move mode and just move it up 10 pixels I think that will basically achieve the same thing here so I'll save we hit play to go into game mode and now it's up there uh but it scales everything by times four I forgot about that so let's actually move it to more like two or three pixels off the bottom so moving at seven pixels down means it's three off the bottom so times 4 is going to mean 12 pixels off the bottom of the screen so that looks like a pretty good placement for our Hotbar and that should pretty much be it for what we need the Hotbar to do so next up one of the things that has been around for a while that we of course need to fix is that we can Harvest nodes just by running into them that's simply because our area which is harvesting the nodes is active even when we are not in the swing animation like this so we just need to make sure that we enable those areas during swing animations and disable it at all other times so let's go to the player scene and we'll take a look at the animation player and we'll also take a look at the area 2D while we're here I've also noticed that there's been this update cash bug in the error log that's just mentioning that these properties are set to continuous when they should be discrete for this pixel art game all properties are going to be discrete which just means that they only update when you hit a keyframe and not try to change the values in between key frames but anyway let's go to swing down animation and we can see that we don't have any mention of the area 2D set up here yet so we're going to have to add a track so let's do a property track on the area 2D and we're going to be looking for monitoring and we're going to turn that off at all frames except the last one where our tool should be hitting whatever node we're trying to harvest so we can right click here and insert a key for monitoring to be on but at the start here monitoring should be off so I'm going to disable that so we right click insert a key and then toggle the Boolean off and then at the end of our animation right here I also want to insert a key and toggle monitoring off again so basically we enter the animation monitoring is going to be off we turn it on for one frame that's 0.2 seconds and then we turn it off again as we exit out to other animations so just to double check that that's kind of how it's going to work here let's look at the hand equip script and we can see on area body enter 2D that's when we're doing the interact with body function basically harvesting the nodes and that means that we need monitoring to be on for that to work so that we don't have to mess with the monitoring settings on every single animation we'll just have the other swing set up exactly like this and we'll have monitoring turn off automatically on ready so let's create the function underscore already and we're going to take the area 2D which we have to get access to with on ready VAR so at on ready VAR area 2D area 2D and we'll look for area 2D in the list of nodes so it'll just jump down one load find that area 2D and assign it so after we have area 2D we want to on ready do area2d.monitoring and we'll set that to false now to note at tool annotation is in the script which means that our code will run in the editor I want to make sure that our code that isn't the setup function here does not automatically do that just because it might cause some problems down the road like it would probably be fine for monitoring to turn off automatically when our script loads but let's just make it so it doesn't it only needs to do that when the game loads so I'm going to do if engine dot is editor hint and we want to inverse that because we don't want this code to run into the editor so it's if not engine.editor is hint then we'll run our on ready code so now it's only going to run in the actual game and let's do the same thing down here so if not engine is editor hint tab this over one bit okay and now the only code that's going to run and the editor is this and all of this is now game specific code so just be careful when you're using the add tool annotation because once again it makes a code run both in the editor and in game so it can be a little dangerous having your properties change in the editor if you aren't careful okay anyway let's go back to the other animations and we just need to repeat this area 2D monitor ring so let's go to swing left add track property track area to D monitoring okay and just the same at the start we come down here right click insert key so monitoring is off go to 0.4 seconds insert key monitoring toggle it on and then at the end point six seconds turn off monitoring once again I think we might actually be able to just select all of these keyframe points with a box select Ctrl C and now we go over to swing Right add a track property track area 2D monitoring and let's see if we can paste it in here nope that doesn't work okay so we'll right click insert key monitoring off at the start on at 0.4 seconds and then off again at 0.6 seconds okay and lastly we'll do swing up same thing add property track area 2D monitoring okay come down here right click insert key turn it off 0.4 seconds right click insert key turn it on and 0.6 seconds by click insert key turn it off okay so now uh monitoring will turn off at the start of our script when the player enters the scene and it will be turned on only at the 0.4 second of our swing down left right up animations so with that we should be able to hit play and if we run into this Rock The Tall Rock it's not going to harvest anymore because monitoring is off but if we swing at it like this you can see that the harvesting actually works again so that's basically all we need to do to make sure that the harvesting works as intended and we actually need those harvesting animations to harvest these resources like the tree so let's run into to here and start harvesting the tree by swinging the ax and it is pretty much working as expected so at this point we already have a pretty solid foundation to the game but there's still more things we could add in here for instance we could add in a particle effect when our nodes here vanish because they've been harvested we could have an explosion of pixels to come out when our nodes are removed from the scene so let's create a pixel effect next I'm going to go to scene new scene and let's look for other node we want particles so we can use either CPU or GPU particles personally I don't know the ins and outs about how these exactly compare but I think on the documentation that you mention that when you have a ton of protocols the GPU particle system can outperform the CPU particles but more or less they have about the same properties you can set up in the inspector I think GPU particles has sub particle rendering but I'm not sure that CPU particles does anyway we'll just go with GPU particles I don't see a good reason not to so we'll use that for our particle system we'll rename this particle system to be something like depleted resources explosion explosion okay if we hover over this little warning we'll see that we need a material to process the particles it's not assigned so basically we need a texture what are we going to actually show for our particles um as the effect so if we want to keep it simple we can just click here and do I think new canvas texture was what I was trying to go with yep and that just gives us like this little square if you want to change the color of a canvas texture particle you can go down to visibility and self-modulate to change this color if you do modulate it changes the color of all child nodes as well but we can change the color here to something else like red or blue if we wanted to but I think just white pixels will do just fine for right now okay so if we hover over the warning you'll see that in order for the GPU particles to do anything we need to have a process material which we can assign over an inspector process material so here we want new particle process material when we do that you'll start seeing the particle system actually starts to do things if you want to edit the properties just click on that and you'll get a whole bunch we can change so one we're going to turn off is the gravity so if we click on gravity we can change the Y gravity to zero and now that's going to stop the movement so then we need to figure out from our origin Point how do we want this particle effect to look where do we want the particles to come out should it just be an explosion and like a ring that goes all the way around should the particles come down in an arc so there's many ways you can set that up so if you want to control where your particles Spawn from you can click on shape and change it to something like a sphere or a ring or box if you want the particles to randomly spawn away from the center point but more inside of another shape like a sphere a box would of course just be like a rectangle and a ring would be like a sphere again but with a center part cut out so you could think of that like a donut but for right now I'm going to leave it as Point uh we'll just see if we can have off the particles start from the center and then go out in the directions we need to so that means we're going to need to set the velocity we can start with initial velocity let's try setting it to something like 50 velocity Min 50 velocity Max now you can see it's coming out of here in like a 45 degree Arc that's because if we look at Direction the spread is 45 so if we wanted this to be a full circle in the direction of the velocity velocity then we can change the spread to 360 because a circle is 360 degrees so now it's coming out in all directions uh but right now you can also see that it is coming as a stream but you might prefer for this to be more of like a burst effect if we're dealing with an explosion that would more be like all the particles coming out at once so if we want all the particles to come out at once then we need to find the I think it's called explosiveness so I'll filter properties because I'm actually not sure where that is so I'll type up here explosiveness so that's in time I guess and we'll take the explosiveness and let's set that to one so now you can see that everything comes out at once so more of an explosion and we can take the amount and increase that as well so if we do something like 20 then we're going to get a lot more particles coming out let's try 30 even um it really won't matter if we're just emitting one pixel particles like this I doubt any machine can't handle that so it's not very complex or anything so if you wanted you could probably do something like 3 000 and get away with it so now we have almost like a complete ring being emitted which is actually quite cool honestly uh maybe a little bit too overkill for what we're dealing with let's try 300 and maybe 150 because I do want there to be some gaps here and I don't actually want these uh particles to come out as far as well so rather than slowing the velocity let's decrease the lifespan of these particles I'll come down here to time section I guess that's where explosiveness was and let's change the lifespan to 0.25 okay that's a little too short let's see 0.5 instead okay so the only way we can really test this for sure to know how it's going to look would be to put it inside of our actual scene so let's control s so I'll create a folder for uh particle effects on the like here I'll just call it effects and then save it and and there now let's go to the game level scene and I'll take the particle effect from the effects folder and let's just drag it in here to where we have our node and this will be roughly how the particle effect compares to the size of the node I think the particles could seem to be a little bit bigger than that let's hit play and uh test to make sure that that's how it looks in game as well all right and I'm going to take this effect and jump into it so let's um so let's first off increase the size of these particles so let's go to scale and for scale maybe we do two and two and then let's shrink the number of particles to 50. and I maybe I want to lower the velocity a little bit as well or uh rather we can keep the initial velocity as 50. but let's actually slow that down over time so I think with damping that's might be what you need uh let's try one and one here okay it does seem to kind of do it let's try changing it to 10 10 30 30. okay yeah and that definitely does seem to be slowing the particles over time so 50 50. okay I think I'm liking that a lot more so we have particles that start off fast and they get slower over time we can also make it so that these particles fade out at the end rather than just disappearing from view all together at once so for that we would need to go to color and then we can make a I think it's a color ramp we want here so let's do a new gradient texture 1D and this will be the color over time so if we click here we can edit the gradient we want to start with white of course so I'll change that initial color to white and let's click here to add another point for our gradient so this will be about the time during our timeline duration where we start to fade out the color and then this final one we'll double click on it and let's lower the alpha to zero okay so now what happens is at the end you can see that our particles actually fade for a second before they just disappear from view so it should be a little bit of a smoother transition out and we can test it by Saving and hitting play taking a look at our game scene and that will be roughly how our particles look after uh we Harvest a node of course we're only going to have it emit once and we only want it to happen once the node is destroyed but we're getting pretty close let's take the scale and I'll increase the size to 3 here for the particles oh let's make it as let's make it a range actually between two and three so I have a little bit of variation between our particle sizes there and let's take the amount down to 40. okay just want it to look a little bit chunkier a little bit more Pixar and lastly we can turn off emitting so what we'll actually do is we'll spawn our particle effect we'll emit the particles one time as a burst and then we will basically remove the node once all the particles are gone so to automatically remove our particle system from the scene I'll right click add a child node let's look for timer uh we'll say 0.5 seconds to remove it and then let's attach a script to our depleted resources explosion so I'll create this new script here and then we're going to need to call back from the timer so the timer go to node click on the signal timeout connect it to the depleted resources explosion and then on timeout we're going to queue free on the particle system so we just need to make sure that the duration for our particles being there is less than the timeout for the timer so that the particles can all finish their simulation but remember we set the time to 0.5 seconds so after 0.5 seconds of the effect should be able to remove itself without any problems if you want you can make it a little longer just as a just in case and do something like 0.55 give it a little extra time let's also turn on one shot and auto start so this will happen automatically okay and now we just need to create our depleted resources explosion at the location where our resource node is removing itself and then emit the particles when that event occurs so let's go to Resource node Pine let's open up the script here and we're going to have an export far for the particle effect we want to spawn after the node is depleted so we can do something like under pickup type let's say at export VAR depleted effect which would be a type of GPU particles 2D and we'll save that okay so now in the inspector we can assign our effect so I'll just drag and drop it depleted resources explosion.tscn into the slot here oh I messed up because it's not in the level yet it's actually a packed scene you have to instantiate the packed scene and then it's a GPU particles effect okay so in the inspector we drag the packed scene into the slot and then we instantiate a copy of that practicing so then we go down here to where we queue free before we queue free we want to spawn particle effect before removing the node and then we'll create the effect and add it to the level parent so let's create a local bar here so I'll call it effect instance which will be a type of GPU particles 2D and we're going to create that by taking the depleted effect and instantiating that okay after we instantiate it we add the location of it to be the location of our resource node and so let me take a look at the effect scene does this have a position we can set a transform yeah okay so transform position we should be able to set that so in our resource node script once again effect instance dot let's see I think we could just say dot position I'm not sure why it doesn't show up there as an option but anyway this will be equal to the position of this node but we add it as a child to the level parent so level parent dot ADD child effect instance and this means we create a copy of the effect we position it at the node we make it parented under the level so that when we remove this depleted node it doesn't remove the particle effect also we want the particle effect to last after the node has been removed and then we just need to emit some particles on the effect instance so effect instance dot emit I'm not sure why um the functions here aren't showing up as an option but just to be sure about the function names we can search help up here and do GPU GPU particles 2D come down here and look at the functions I guess GPU particles doesn't actually have an emit function not a problem so what we'll do is we'll just make sure that by default it is enabled and then we'll just make sure the emission only happens once during that 0.55 seconds so maybe we have the loop be one second but the particle system removes itself after 0.55 seconds so it'll only ever emit once anyway so let's open up the depleted resource node scene um and we'll toggle emitting on and oh actually uh the one shot here that's that's what we want so we just do a one shot and when emitting is done then it's just going to turn itself off automatically so that's actually pretty much perfect for what we need there all right so that might actually be everything we need just these three lines of code let's make sure that the rock also has it so it will filter files resource node resource underscore node and we'll change rock tall to use that same effect so we can load a effect from our effects folder and we'll do depleted resources explosion okay so now they both have that same effect Let's test it um let's go to 2D level and make sure that the test depleted resources explosion is removed from the scene that shouldn't be there by default it's only going to happen after uh one of our resource nodes finishes and then we'll have the explosion so let's hit play we'll go Harvest this rock one two three four five and we didn't actually get the emission to occur Okay so we'll have to figure out why that is let's try editing uh the depleted scene first and see if anything is going on here so emitting is actually off by default now so it maybe actually we just need to turn emitting on since the one shot occurs and stops in the editor I guess so script View and we're going down and looking for resource node and then for the instance the effect instance effect instance we're going to take emitting and turn that to true so let's see um emitting equals true okay let's try that I'll turn off this breakpoint we'll hit play we go here and harvest the node one two three four five and we get our explosion sweet so let's make sure that is also working with the tree one two three four five and we get our explosion so now we can just basically tweak our effect to what we need it to do but um our particle system is uh basically working there which is pretty cool so a couple things I might change increasing the size of the scale so let's try four and five and let's also increase the initial velocity a bit more to 60 60. and I'll test it one more time let's go Harvest to node one two three four five and there's our explosion so that'll do pretty good for right now so at this point we have a pretty functional resource Gathering system for our game we can Harvest nodes when the nodes are depleted they'll explode with a particle effect we can switch to different tools with our Hotbar swing at a different node and the only inappropriate tool will be able to harvest the right node so I think just to kind of wrap up for fun we could try to expand our game level a little bit add a few extra types of nodes and different terrain that we can walk on and that'll pretty much be it for this mini series on creating a gatherer RPG so one thing that would be pretty cool to add to our game to make the world a little bit more lively would be animated tiles so we can add a bobbing raft that we can walk across to get between our aisles using the textures that are in the gatherers exterior pack so here I have floating platform.p G so in order to add the raft I would drag this into the tiles section for the tile set um so if you don't remember you just make sure you have tile map selected go to tile set View and it will be right here so drag this over here and when you get would you like to create tiles automatically this time hit no because we're going to be creating just one tile but it's going to be animated so now go to setup view make sure that your texture region is set to be the size of your tiles so 16 by 16 is what I need here so I'm just going to left click on the first tile and rather than creating the other tiles here what I'm going to do is go to select mode select my tile and then animation frames we want to click add element and the next tile will be automatically added as part of this one's animation so do that two more times for a four frame animation and we want to set the duration for these frames for how long each of them should take so I'm thinking something like 0.2 seconds should be good so 0.2 and then type a few times 0.2 so on and so forth 0.20.2 so that'll make a 0.8 second long animation to draw with this animated tile okay so now let's go over to tile map mode make sure eraser is turned off and make sure that you're in selection mode so you can hit Q for that and I'm going to be writing these onto the top layer so that it doesn't override any of the ground so top and I can just basically place the rafts where I need it so like so and you can see that already in the editor that our raft is animating now it's moving a little fast so I'll go back to tile set view click on the tile editor and then go to the frames let's make it 0.3 seconds for each of these you can of course have different timing for each frames if you want but that's how you can take a animated Sprite sheet and turn it into a tile animation for your editor so let's create a couple more rafts that will lead to more Islands kind of like so now the way that I had the Collision set up for the water was that all the tiles that are water have collisions except for the ones if we go to water view here and tile set water that are using the alternative tile so I'm going to draw the alternative tile under these rafts so that I can actually walk under them so let's do that for all of these water tiles okay and then save the game level and let's hit play to test and we should be able to walk onto our vafs as you can see here so this one I must have missed a tile but let's keep going and check out this over here we can get onto that Island so let's stop The View and finish up that Collision change for the water and if we go back into play mode actually um what's causing the block here is the ground tile itself but because the water tile already has the collisions I can actually just remove the Collision from this ground here because it's the water that we really need for the collisions so let's go back out I'll edit my tile set let's go to tile set grass and these tiles here these three that already add their physics layer set up we'll just remove the Collision shape here so if we hit C to clear we can left click on each of these C clear see clear and that should just remove the collisions from those so now if we hit play again we'll go down to here and you can see that the water under it is still blocking our movement but if I go here where we don't have that water Collision tile but just a normal water tile then we can actually walk in exit our Island so just a little bit of tweaking to get that needed and now we can basically walk over the water where we need to so just to add some extra tiles and for fun uh let's do the decor grass style set drag that in here it will automatically create tiles for this and then we can just draw some tiles where we need them to be so on tile map I will do this on the top layer so that we can draw onto the grass we can actually select all of these tiles if we want and then let's go to random mode and then just left click where we want to have some random doodads show up in our game world so just an easy way to add in some more detail now let's add in another terrain so I'll have tile set desert and we have to be in tile set view for that so drag tile set desert into here automatically create the tiles and basically if we just kind of repeat the steps so we'll take these tiles and we'll draw whatever island shape we want so I can do something like this here then we'll have the edge tiles where we need them to be so let's get all of those going these tiles are pretty simple to use so it should be quite straightforward just kind of where there's an edge then it should show an edge and that's pretty much it so let's do the top bit here so corner corner and then the edge tiles so then we might also want to place some additional objects into the game world over here um to kind of organize our game level let's right click and I will add a child node let's do a node 2D I'll rename this to be boiled objects okay and then let's just drag all these resource nodes into there World objects okay and now if we need to we can minimize this menu um so that we can see the important stuff in our game level so let's add a cactus to our desert and I'm going to save this Cactus as another scene let's go to objects and I'll just create a folder I'll call this uh doodads so this will just be for objects that aren't placed by the tile map but also aren't necessarily harvestable so okay then we can just call it Cactus one I guess let's jump into the scene and all right click on it add a collision shape let's look for body static body 2D right click on it add a child node um so we need a collision collider so a collision shape 2D we'll click on shape and let's do a capsule shape just make it make sense for the object we're creating a collision for remember that the top bit is kind of above the ground so we only need to create the Collision where the object touches the ground with this top-down perspective so you can save that and go to our game level we can see that this still has a collision shape so we can duplicate it and move the duplicate over here we can also go into the doodads folder and duplicate the cactus for let's say uh Cactus 2 and jump into Cactus 2 so we just need to change the texture out so let's load from art gathers exterior objects desert and we'll have cactus 2. okay now we can go back into the game level and then we can drag a cactus 2 into the scene now make sure that in these scenes you actually reset the transform to zero zero so when we're placing the nodes they should be wherever our cursor is centered so rename that there and we can also call the node Cactus type 2 if we want go into Cactus one change the transform of the base node to zero zero here as well then I'll rename the node Cactus underscore type 2 sure let's go to the game level and now let's make sure that our Cactus nodes get placed correctly so I'm going to drag this one down here and then we can drag a cactus type 2 into the scene as well okay maybe next we want to use the desert tree so let's create a desert tree that we can use as a resource node by duplicating our resource resource node tree pine so I'll duplicate that and let's just call it tree desert we'll jump into that maybe the tree desert has a starting resources of seven we'll leave the pickup type of the word the same it's still a tree maybe we could change the color of the wood to represent a different type of wood and the depleted effect everything else would basically be the same um just got to look at our node here and change the Sprite really so for sprite 2D we're going to load let's go into art gathers exterior objects desert and then let's grab the Savannah tree I'll be named this up here to be Savannah tree and maybe well also call the scene file uh tree desert Savannah just uh being a little bit more specific there okay and the Collision shape let's expand that make it a little bigger this tree is bigger so we want it to be kind of centered there okay and then basically we can just go to the game level and we can bring industry kind of like so and let's bring in a couple of them oh the the last thing that we might actually want to change as well and the center point here that's the position that it's going to use for the explosion so we may actually want to come in here and edit it we can move this Sprite up a bit so the Sprite 2D I'll hit W to go into move mode Let's Move that up so the center point is the actual location of the tree so I kind of want the base of the tree to be centered there and then let's move the Collision shape up there to the center as well so now if we check game view that's going to update the positions a little bit for our nodes so let's adjust those and uh tree two tree three okay two two some something like that okay now let's hit play we can go down there and we can Harvest from our trees okay a couple clean up things let's also take these resource nodes and move them into uh World objects also take the cactuses and move them inside of that as well and I can close the World objects uh menu we really only need to drag and drop stuff into that and then lastly on the tile map for tile map if we look at the water layer there's still water under here and because of the way everything's set up we actually want to remove those water nodes so let's use the erase tool and we can use pencil mode hit Q actually let's use the vect mode it'll be quicker and then just drag a box here to remove the water tiles under there and there as well so that'll make it so that we can actually walk on this ground if we hit play now we can go down and walk onto our Island we'll switch to the ax and we can Harvest our tree three four five six seven okay yep and this one as well one two three four five six seven okay another thing that's kind of going on here the hot bars ended up uh below the screen so if we took it if we if we go out take a look at our game level we can see that's the case here our hot bar is showing off center by a bit so if we look at layout and transform we should be able to reset this transform like so and to make sure that we don't accidentally mess with the transform here I must use the move tool on this Hotbar node let's take the Hotbar node and let's lock it into place here also take the resource display and lock it as well I just make sure that we don't mess with those the positions on them so if we hit play we can go back to our main game View and we can see that the position is corrected for that so we can still like switch to you know the different tools and use them on our trees just like we would have expected before gather all the resources so here we can see one issue I created which is that we need to make sure that the World objects actually can sort based on their y position let's see if we can test that out in the editor right now by going to remote view expand World objects and then let's go down here to why store enabled I'll check that and now if we go back to the CNB you can see that our character can once again sort based on the Y position so that means in the actual editor when the game stopped we just need to take World objects let's go to ordering and check why sort enabled so that will make all the child objects also sort based on the Y sort uh just like the game level already had setup so just for fun I'm going to add in another biome over here to the left so let's go to tile map view let's see if I can find the dark Sprite sheet right here so tile Set Dark I'll drag that into tile set view automatically create the tiles okay that's done now we can go to tile map on the ground we want to come over here and just kind of lock the position of the tile map as well yeah okay so ground view view for selection mode uh turn off eraser tool and I'll do rect select so I can draw some ground easily here and then let's do the side tiles okay zooming in a bit might help actually then we have the bottom tiles and lastly the top okay these little corner pieces too okay so that pretty much looks good so now let's add another type of harvestable tree I'll duplicate the pine and let's do tree dark let's open up that scene we'll change the Sprite node here to be something else so we'll load from the project and art gathers exterior objects dark and let's grab a tree here um suppose we could just use the kind of bushy berry-like tree and the Collision shape is probably okay as it is to make things a little bit more interesting rather than just harvesting normal wood let's make a dark Ward so not in resources types but in um pickups let's duplicate the pickup frown Ward to be pick up a word dark so double click into that and then let's change the icon here so I'm going to load art gathers exterior let's see resources wood gray and then for pickup wood we need to change the resource type so we had that in items resources Resource Board so we'll duplicate the resource and I'm going to call it Resource Board dark and we can double click in that resource and we change the display name to darkboard or change the texture to Let's load that same texture file so resources wood gray and I'll change the resource name down here to be dark wood okay so now in pickup Ward we just need to set the Resource Board dark as the actual pickup item okay and now we go back to this dark tree I'm gonna rename it we'll call it dark tree uh but actually in in this scene I can see that I edited the wrong one this is the tree pine so I'm gonna actually don't save this scene and we're gonna repeat the step with the um tree dark Okay so basically here we just change the pickup type so let's load a pickup type from the project that would be in objects pickups dark wood okay and then the node is going to be called Dark tree and the Sprite is going to use the dark tree Sprite so art gathers exterior objects dark uh dark tree small okay now we can save that let's take a look at the scene here and make sure that the pickup is the right scene so I'm going to open that scene okay and that is the dark wood okay now we can go to the game level and I'm going to place a couple of these dark trees and let's just pop them in there kind of like so I'll move them all under World objects let's finish the bridge here so in tile map floating platform We'll add these to the top layer so make sure we're in pencil mode uh turn off random again and then add those rafts so we can get over there then we need to change the water and just remove the collisions so water tiles use the alternate tile and then just paint over the spaces where we should be able to walk and now we can hit play I'll be able to walk over here to the Dark Island and also don't forget to remove the water tiles under the island or you could change them to the walkable water if you want it probably doesn't matter actually so if you want to use walkable water we could just drag this for the size and shape of the island like so you don't ever be able to see it so it won't make a difference here and then now we should be able to walk onto the island like so and harvest our tree and you can see this is giving us now a different type of resource this is the dark Ward which is different from the normal wood we get over here so you can see those are adding different inventory slots then we have our Stone as a third option and if we want to make the Dark Island a little bit more interesting we can add in the decor tile set into this and make sure you're in tile set view decor yes automatically create and let's draw some of these Decor tiles onto here on the top layer so I can place some flowers some mushrooms some random Sparkle dots maybe a summoning Circle and some colorful flowers and basically caught good so we can of course walk onto that island and see the Cosmetic changes there okay so pretty much in a nutshell that is just about it for the setting up the basics of a resource Gathering game inside of the Godot engine if we want to go through everything one more time we have our main character who can swing a pickaxe of course Harvest some resources you can change which tool is equipped to his hand and of course the animations update with that correspondingly so we can keep harvesting different types of resources different tools are used for a different resource nodes so okay well that's a tree but this is a stone so our ax cannot Harvest it we can walk across Bridges and go to different islands in the top left we have our resource counter so these are the resources that we added to our character's inventory and if we come down here we can get a different type of wood so we have three resources and of course as you've been seeing whenever we finish harvesting a tree like so or a rock we get that particle resource explosion so that is pretty much going to be it for this tutorial on creating a resource Gathering RPG inside of the Godot engine I hope if you watched from beginning to end you learned a heck of a lot about the Godot engine and how to set everything up inside of it so I've been Chris that's going to be it for this video series thanks for watching to the end and I will see all of you in my future your game development content
Info
Channel: Chris' Tutorials
Views: 27,492
Rating: undefined out of 5
Keywords: godot 4, free godot course, godot tutorial series, godot 4 tutorial series, survival game godot, rpg godot, top down 2d godot, resource gathering, resource collection, item pickups, godot, godot engine, gdscript, game development, godot 4 tutorial, godot tutorial, gdscript tutorial, gamedev, godot 4.0 tutorial, godot tutorial 2d, godot beginner tutorial, how to make a game, how to make a game in godot 4, godot 4.0, game dev, godot game development, godot 2023, gdscript 4
Id: nQluyQ-1wSI
Channel Id: undefined
Length: 225min 32sec (13532 seconds)
Published: Tue May 23 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.