Godot Top-down Shooter Tutorial - Part 16 (Tilemaps and Autotiles)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everyone and welcome to part 16 of the Godot top-down shooter tutorial in this video we are gonna cover adding a tile map to your game so we no longer have this gray background for our game plus we're gonna focus on how to add collision shapes to parts of your tile map so that our player and bullets and whatever else collide with walls and buildings that we add to our game so we'll be going over all the different ways to use a tile map all the different types of tiles you can create and this is just gonna be a general basic overview of how to use tile maps within Godot so hope you're excited and with that let's get started so as a note as we get into this tutorial I'm gonna do my best to give you an overview of how to use a tile map in Godot so that if you've never used it before you should feel comfortable to start using it in your game but tile maps are a pretty complex subject there's a lot of things that you can do with them and a lot of features that aren't easy to just cover right away so it'll be good if you're still curious or feel like there's more you want to know to look at other tutorials or look online for more resources about how to use tile maps that said let's get started so if I come over to our main scene here I'm gonna first create a new node and I'm gonna call this or I'm gonna search for tile map and so a tile map is the default container for all tile maps and tile sets in Godot you always need a tile map at least one when you want to use tile sets and so there's a lot of things you'll see once we create our tile map here first I'm gonna call this ground and typically the way that I use tile maps and this isn't a hard and fast rule you can adjust as needed in different games are gonna have different needs but I will usually have a ground tile map where I just put a default ground layer I'll then have another tile map that I call ground overlay or ground decorations and this is where I'll put dirt and flowers and some other things just to give a bit more variety and then if I have things like walls or trees or other things I will typically have another tile map layer where those things are housed so the first thing we're going to do just as a tile map tutorial is make our ground so when I create our tile map you'll see a couple things over here you'll see a mode which is square whenever you're doing traditional 2d you want to use square isometric is when you want a 2.5 B you know kind of an isometric feel to your game we don't have I stress and metric tiles so we are just gonna use square we'll see Tulsa empty so this is a resource we're gonna create in just a minute and then you'll see a couple other options here we don't need to worry about those we do want to worry about cell so we'll come back to this in just a second then there's collision occluder so one of the cool things about tile maps in Godot is that they have built-in support for collisions and for light occlusion so you can add shadows and collision shapes to your tile map just by default which is a really awesome feature about Godot so let's get started actually making our tiles first thing I'm going to do is click this empty tile set and say new tile set and then it'll create a new tile set resource and I'll click on that and then we will see the tile set editor pop up here and this is gonna look really familiar to you know the animation editor the animated sprite editor it's just kind of the standard Godot sub editor so we need to actually add in a sprite or a tile sheet to use as our tile set so I'm going to hit this plus button here which will let me select what we want to use you can see I've already got it open over here we're gonna go to assets top down shooter tile sheet umm and by the way if you've got the Kenney Peck make sure you use tile sheet and not sprite sheet the sprite sheet has space in between all of them but the tile sheet they're all packed together so that's what we want to use I'll just use the top sheet complete and then you'll notice that we've got the tile sheet visible down here now there's a lot of extra options you can get with this but in order to access them you have to actually create a tile so let's kind of go over this interface for a second and talk about what all the options are so you've got your you know zoom in zoom out buttons here you've got tile info you can toggle on or off I like to keep that on and you've got three buttons up here that let you create new tiles so I'll give a brief overview of each one and then we're gonna actually go through and give an example so new single tile creates a placeable tile out of something in this grid so if you just have one like a unique one-off tile you want to make so if we come down here we'll see this this toaster right say we want to place a toaster in our game well we can create a new single tile and select right here but to have a toaster tile now one thing you'll notice is that I have to manually drag and select which we don't want to do right like our tile set here our tile sheet is all uniform size so we know what size our tiles are and we want to get some snapping to this so now that I've created a tile you'll see there's some extra options that pop open I'm not totally sure why these aren't there by default but sometimes you just need to create a tile for these to show up so I'm gonna hit enable snap and show grid and all of a sudden you'll see a grid here and now if I drag it'll snap to the grid which is what we want so you'll notice that our tiles are like half the size we want it to be this toaster should be one tile but it's currently four if you can see these little blue lines here so in order to change that I'm gonna come over here to our right where there's some new things that have opened up some new options I'm gonna select snap options and change this to be 16 so this oh whoops nope take that back 64 I was thinking the wrong way okay so this tile set from Kenny is all 64 pixel tiles both ways so now that it's 64 you'll see that each in unique square here of our tile set is an individual tile so if I select this toaster it'll just select the whole thing so you can use this step here to make your grid fit your tiles now say you had some space between each tiles so there was you know like a one or two pixel marginal margin in between each tile you can use separation here to account for that so it'll space out your grid tiles by by like accounting for space in between them so Godot tries to give you a lot of options to work with different tile sets personally I have had issues in the past even with separation trying to get tiles to work that have space between them so I always prefer to use tiles that are packed together they do not have space between each individual tile or image on the tile sheet then there's some options for the selected tile here so say I want to give this tile a name I can call this toaster so now it's got a name you can modulate this specific tile it won't change what it looks like here but when you actually place that tile in your game this modulate property will be applied to it I'm gonna reset that and there's some other offsets z-index things you can do here so just an overview this is how you create a tile now single towels are great but when you're making a game map you don't want to place every single tile by hand that's really difficult it takes a lot of time and it just kind of gets rid of the value of using a tile map so next we're gonna look at Auto tiles which are one of the more complex features of tile Maps but also probably the most useful as far as making a map for your game okay so in order to demonstrate how we use Auto tiles I'm going to scroll over and find just our generic Wooding wooden building tiles so you'll see all this set of tiles in here that kind of have a wood exterior with kind of this darker gray interior and so what I'm gonna do here similar to what we did with the single tile is I'm going to click new Auto tile and then I'm going to drag throughout this entire region and even though we're probably not going to use some of these tiles that's totally fine we will just include them anyway and so now that we have this selected I'll change his name to B I will say wood whoops wood building one other thing to note too this is what I mentioned it I do recommend having this display tile names info icon on because now we can see if I have this on this wood building tile as well as our toaster but if I turn it off you can see the outline but it's not totally clear just where where our tiles are so this the tile editor the Tulsa editor in Godot this UI is perfectly usable and I pretty much use it in all of my games that do have a tile map but there's still some finicky things about it one thing to know is that if you click off like if I have this wood building selected right and I click off somewhere else like it can chain where my tile my Auto tile is or where my current tile set is so we've we've just lost this whole wooden building thing over here it's just moving where I click so just be careful with that and if you do click off where you want your towel to be that is totally fine you can just reselect it so oh that's a now we have a wooden building here and it's selected so if I go over to my ground tile map here we'll see a couple things one is we have our toaster which is great I can select and place toasters wherever I want which is again the most important thing that our game could have but if I have our wooden building and I place it it just always places the top like a top left cornor tile it doesn't ever place the right tile so we need to define some rules that tell our tile map which wooden building tile the place based on which tiles are around it so if I get rid of this we can come back into our tile set here click on our tile sheet and start defining some of those rules and the way we do that is through something called a bit mask and so a bit mask basically lets you draw which parts of a tile should be drawn depending on what other tiles of the same type are around it so basically it's saying hey if I know that I have a wall on the tile above me I should not draw a wall I should not draw a tile that has a wall at the top so if we have this tile right here that I just clicked on then and I put a tile to the right like I should not draw a tile like this because I know that we have the same tile or tile the same tile set to the left so you're basically defining those rules and gadot will use that to paint in the correct tile so with a bit mask what it lets you do is click on different parts of a tile to draw in what you want to think about it as where like where someone should be able to walk like where the collision should be that's not always the right way to think about it but in this case like I want it so look at this this like little corner or center piece here if I am a actor in our game like the player or an enemy I want to be able to walk here and here and here and here and here and here and here but I should not be able to walk in the middle here and when you do that you're basically defining the rules of where that tile will get drawn in juxtaposition to other tiles in the same tile set so if I were to follow that same pattern I'd click here for this one and I click up here for this and you'll notice that this isn't super correct like right now I can draw for bitmask little squares within a tile like if I click on four different corners but our tile set isn't that small like we have a lot of little intricacies here so I'd really like to not draw these two corners but be able to click in the middle here for this one so gadot lets you do that and you can actually change the size of your bit mask like squares that you draw also one thing it's left click to draw these and right click to get rid of them so what I need to do is change our auto tile bit masks these options over here under select the tile change this to be 3 by 3 3 by 3 minimal 3 by 3 gives you is basically you draw the same way as 3 by 3 minimal but you get a little bit more control over how those tiles are are grown but it requires a lot more tiles in your tile set to actually draw correctly so typically unless you have a huge tile set I think it's 256 tiles or something crazy like that that cover every single option like every possible permutation you usually wanted to do 3 about 3 minimal so if I select 3 by 3 minimal and now try to draw on our tile set we'll see that I can select 3 3 different sections three different squares in each direction for auto tile which gives me a lot more fine-grained control because now I can say I should be able to walk in every part of this except this little corner and I can do the same down here and just draw on through here okay and I'm not gonna do all these but I do want to draw just enough to give you a demo one thing you want to do too is find the default square I think there's one in here somewhere is it this one might be this one okay I'll just do that oh no it's this one right here okay so just find the like the default like this is a single tile there's nothing adjacent to it and before we go on with this one other thing you can do is select the icon tile and this is basically selecting the tile that represents the entire tile set so it's the tile that when you look here will show up in the actual tile map editor and so for us like I usually select this option here like whichever one is the self-contained tile that has a border on each side just so it's clear like what tile this is and this becomes the default tile that auto tile will draw if nothing else matches the mask if it can't find the correct bit mask so anyway let me just go through and I'm just gonna draw the bit mask through a bunch of these tiles and then we'll see it working I won't speed it up because I'm just gonna try and do this quickly hopefully it makes sense how I'm choosing which areas to draw the bit mask like I said a very simple way to think about it which is usually correct as just think about it where someone should be able to walk you wanna you basically want to you can draw it either way like you can draw your red wherever your walls are or you can draw them wherever the walls are not but just make sure it's consistent here I'm choosing to draw it where walls are not so whenever there is a third like a small section that does not contain a wall part of our tile set that is where I'm going to draw our bit mask here so let me just draw these and I think this should be all we need so one thing to note too is that working with tile maps is kind of tedious there's really not a way around it it does take time and effort to get this and it's not just Godot it's really that way in every other program or game engine that works with tile maps they just take some work it takes a little bit of setting up to get corel so if you're a little discouraged about how long it's taking do not fret it's just natural it's part of working with tile maps so it just takes some time to get used to and I think we've drawn everything we need to one other thing to note is that you usually don't want to use all the tiles in tile set like some extra will come so for example here we already have our tile which is just self-contained that has no borders we could do the same thing here and draw on these but we don't really want to use those in our game right now we just want to use this one so it's okay to leave some of these empty in same here I believe we've already got a tile where we draw this like just this single Center box somewhere so I'm just gonna not draw over these ones here and they just won't get used which is totally fine okay so I was kind of rambling there I hope that explanation makes sense at least enough that you you feel comfortable using this on your own and now you'll see because we set the icon tile this this contained wooden like the one with just a wall on each side will be our default tile here and now if I draw well actually see Godot is being smart and knowing which tile the place based on our bit mask and this works for a whole variety of different options here and so if I start drawing around will see that it correctly maps out the right tile to use and it's using that there which is really really cool so all of a sudden we don't have to place all these manually Godot is smart enough to know which one to use based on what are like which tiles are surrounding it so this is really cool and this is a good step but there's even more that we can do with tile maps to make making a game map and editing and adding collision shapes and all the other stuff we need to do even easier and even better okay so now that we have our tiles are our building Auto tiles setup I'm actually going to erase all the tiles we added here so within the Godot editor if you're looking at a scene and you have a tile map select and you can left-click to draw tiles and then right click to delete them so it's pretty consistent between the tile site editor and actually placing them on your game left click the place right click to remove same for a bit mask same for the actual tiles you have here and one helpful thing is that if you shift-click you can draw straight lines and if you command shift click and I'm assuming it's ctrl shift click on Windows but for Mac its command shift click you can draw squares so I can move this around and draw a square so it just makes it way easier to draw your tiles and Godot still uses your auto tiling rules no matter what type of brush you're using this also works for getting rid of so if I command shift right click I can get rid of multiple tiles you know within a square anyway so do that I'll get rid of all these so I had previously mentioned that we wanted to have separate tile Maps for our ground and for our walls and potentially another one for ground decorations or overlay so we don't want to have our walls on our ground tile map but we want them to use the same tile set resource which our tile set is what has all the individual tiles defined so what I'm going to do is hit command D to duplicate our ground and I'm gonna call this walls or buildings you can call it whatever you want and you'll see it still has the same tile set which is good because if we edit or add tiles to one of these we want all of them to be able to use it one thing we could do is just save this as an actual tile set resource that we could load in but it's fine to do it just like this for now so we have our wall setup and we know that if we draw walls we will get a building its gonna look how we need it and so we're good to go there but let's actually get our ground set up in our grass and dirt and everything and in order to do that we're gonna come back into our tile set and talk about the last type of tile that we haven't gotten to yet which is an atlas tile so the difference between an auto tile and an Atlas tile is that Atlas tiles do not automatically draw based on rules that you set like a bit mask but you do specify multiple tiles and you can have it randomly pick which tiled use based on a priority system so how that'll make more sense in just a second when we actually do it so I'm gonna click new Alice and I'm gonna drag our four grass tiles here so the purpose of this is that we have four different grass tiles and we want to randomly use all four of those so that our grass doesn't all look exactly the same we want it to look unique and have some variance so that it just doesn't visually appear weird you want it to have some difference between each tile and so we want to have a way to tell Godot to just automatically choose one of these four tiles whenever we put down a grass tile and so I'll select our Alice tile here I'm gonna call this grass and so you'll notice there's no bitmask option for an Alice tile but there is a priority option and so if I click on these you'll see that each tile within our this this Atlas tile we've defined has a one out of four priority and gadot automatically generates that it says it looks at how many tiles are part of your Alice tile and then evenly distributes the priority for each of those so what this means right now is that each of these tiles has a one out of four chance or a 25% chance of being drawn and so this means we're gonna get pretty much even distribution automatically between all four of these tiles but let's say we wanted this tile to be to happen most of the time and have all the other tiles appear just kind of randomly you might do this if you had an empty grass tile that didn't have these little flourishes on it and you would want that to be the majority and then every once in a while have little you know variations or pop-ups so what we can do is edit this number and I could say I want this to have a three out of four percent so this is gonna have a 75% chance of appearing and the others will have a lower percent gadot will automatically do the math for you and say okay if you bump this up to three that means it has a fifty percent chance of appearing and all the others are now one out of six so it's a really neat way to kind of automatically handle which tiles you want to appear in one and what priority and if I switch that back to one you'll see it resets at all so who a lot of talking but that's basically Atlas tiles in a nutshell and there's a lot of other things you can do with all these tiles we haven't talked about collision occlusion navigation we will get to collision at least today but there's a couple other benefits of using Atlas tiles and we'll see that if I come back to our ground here we will see that if I select an ALICE tile it actually is going to open up a sub tile editor here so I I can just click and paint our Atlas tiles and you'll still see even though we define the priority these are all the same tiles right now it's like always got this little top one right here like it's drawing them all the same what we need to do is actually check this an able priority and that means that it is going to automatically determine which tiles it's going to draw for us now this is really neat because you can toggle this on or off at any time and it lets you have manual control over tiles if you need so say we wanted to just put down a blanket layer of grass that gadot automatically picked for us but then we wanted to later on go through and do some visual or manual detailing and change it up just to make it look better well we can tick off enable priority and then manually choose which of these four tiles to place so this is a really good way if the automatically generated thing isn't quite looking the way you need it to that you can go back in and actually edit those automatically generated tiles and put a layer of manual polish over them so just a really cool thing about how you can do that within Godot so if I have enable priority checked and I draw this a whoops I right clicked and I draw this will see that it's gonna randomly generate tiles so look at this we've got only two flourishes here different two here we've got the big one here so it automatically generates it and it just looks better it just looks good one thing I'm gonna do too is drag our ground at the top of our scene tree so that it appears underneath everything and now if I open up our game will actually see we have oh no oh whoops I'm so dumb I didn't even realize I did this I accidentally dragged our ground to be of her camera I meant to just put it in our scene oopsie so anyway now you'll see we actually have ground to walk on which is great it's just a small thing but it adds a huge just like layer of polish to our game and so what we're gonna do just to give our game some extra feel and make it so we're not just walking on the void this empty grey screen I'm just going to drag our grass tile on our ground tile map make sure this is ground and we're not doing out in walls I'm just gonna drag it over a big swath of our game and just to make sure that for the most part it's gonna be really hard for our camera to not be surrounded by grass we don't have barriers on the edge of our tile map and placing tile Maps does not automatically limit where the player can move so don't don't assume that we're getting that for free but what this means is that just by default the player is gonna have to go out of their way to see a place that isn't grass so this is nice we've just made it so our game actually has a background and we're ready to start adding walls and some other decorations on top of it to make it look even better okay so now that we have our basic tile map functionality here and now that we've covered the three different types of tiles that you can use and when they're good and what they're good for let's actually start making our tiles be interactive with in our game let's add some collision let's start building out our actual map and make this something really cool so one quick note I want to say is you might notice if you're using a different tile map that your tiles don't actually cover the entirety of a square here which is one thing you want to make sure is that your cell size matches your sub tile size so if we have a cell size of 64 that should match whatever our sub tile size is here so you want those two to be the same so that you are always like they're always in step with each other and again don't feel like everything needs to be uniform you know you have manual control so if I come through and I want to add props later but I'm doing it within a tile like say I want to add toasters throughout her game I can select this and choose like at like right now it's locked to the grid but I could potentially change our cell size or take off our like locking to kind of move it around or I could add an offset to our toasters so there's a lot of things you can do to give your tile maps not just a rigid grid feel another thing I usually do is I don't even if I have a lot of props I want to add that come in the same tile sheet that I'm using for my tile map I will do props as separate just sprites or like kinematic bodies or static bodies and not include them in my tile map just have more fine-grained control over how I can move them around so just because you have things like props you know barricades are like crates or something in your tile map in the same like sprite you're using for your tile map don't be afraid to to use that same sprite just for regular objects like kinematic bodies or static bodies or something like that so the core point of all that is do what you have to do to make your game your game you know you there's no right way to use the editor there's no right way to use Godot and there's no right way to use tile maps you need to use what it's just tools there at your disposal to use them as you need to so we've got all three types of tiles here but we don't have as collision and we don't really have any decoration like it's really nice that we have grass here but it's kind of boring and it's kind of bright too like it kind of just stands out so what I want to do now is add two things I want to add some dirt or some other ground tiles that we can use and I want to add collision shapes to our walls so that we have some obstacles the player and enemies have to move around now with that said remember that we do not actually have real path finding in our game we just tell our AI units to move in a straight line and we don't have smart handling for that so if there's something in the way they're just gonna keep running into the wall and not get around it so we're currently somewhat limited by our path finding ability so when we design our level layout we need to make sure a straight path exists from one base to another so that's something I want to tackle if we get time is to add actual pathfinding but for now just keep that in mind that if you try and add obstacles or things that have the player and enemies have to move around you're gonna run into problems because they're just gonna run straight into it okay with that said let's get into adding some dirt we'll start with that and then do the collisions afterwards so I'm gonna duplicate our ground tile map again and I'm gonna call this ground decorations like I said sometimes I call it overlay it really just depends whatever you prefer and again we could just do this in our ground tile map and just paint over our grass I just like having a background tile map that's just one thing because I think it makes it easier to detail over later on it's a little bit weird when you have square tiles because it's hard to make transitions between tiles that take up the whole Square and this Kenny tile set we're using is great it is amazing and it's free but it doesn't really have good transitions so like if I add a dirt tile it's just gonna be grass and then dirt it's gonna be like a straight line transition it's not gonna look super good so when you have a tile set like this where there's not transitions or like intermediary tiles to kind of make it look better one thing you can do is have a separate tile map that sits on top where you actually have your dirt or your decorations or whatever you want to have and you can add some like you know slightly transparent tiles or you can modulate them in and out and separate them you can just do some things to make it look better and give the appearance of kind of fading from one tile type to another even if you don't actually have those transition tiles so oh that's a what we're gonna do now is coming to our tiles up click on our tile sheet we're gonna add a new Alice tile and I'm just gonna drag this over our dirt tiles here I'll call this dirt and that's pretty much all we're gonna need to do here no collision we don't need to change the priority just one out of two is perfectly fine and so what I'm gonna do is not change our ground tile map but I'm gonna select our dirt tile within our ground decorations and I'm just gonna for now I'll just do a straight line out whoops I should do a square and I'm just going to kind of draw this through and around our bases I'm just gonna draw like a little bit of extra tiling just to make it clear like hey this is our base and I'll just draw the same thing over here I'll just draw this so again just a little extra polish to kind of make our bases stand out and to give a little bit of variation to our game now this all said I'm gonna need to move our bases a little bit just to make them line up with this but at least now you know there's a like we have a path forward and I'm just gonna make it kind of died out here a little bit and this is where I said like you know you could do you could do something like having a better transition between these but this is what I meant were the the transition from square tiles kind of looks weird it's just super quick you know there's no in-between here so something we could do is try and add some tiles that are modulated or do something we could have another tile map that's like transitions just thoughts there's a lot of things you can do so with that in mind let's real quick take our bases capturable base let's move this right here let's move this right in here just to move these into the middle I'll move this into the middle as well okay perfect so we've got kind of a path right now that our units are gonna walk on oh this one's a little bit bigger but not a big deal and yeah it's it even though it's a small thing it still looks a lot better and then it previously did and now it's just like it's easier to get your bearings because you can kind of see where the dirt is you can see where the base is it makes it a little bit easier to see the base because it stands out so small things but we are already adding a huge extra layer of Polish and man we got to figure out there's definitely a bug causing that's a bug too but there's a bug causing our enemies to just run like straight to the last base so we will figure that out eventually but anyway so be yeah so I think we've pretty much got it for a ground and again just my preference I like to have just a ground layer that is just straight grass or whatever your base tile is and not change it and then use ground decorations to actually add the overlay for that so now we are ready to add collision to our walls so in order to just demonstrate this one let me just select our walls here and I'm gonna keep our our walls near the end of our scene tree because we do want them to get drawn above other things and there's there's a couple ways to handle this there is a why sort node we can add which sorts all of its children based on their Y positions you can also toggle Y sorting within a set within a tile map so say you're using a tile map - you have like trees or something and they're not drawing on top of each other correctly you can use you can automatically select the y sort to have individual tiles drawn on top of each other based on their Y position so usually if you're doing a top-down game you don't really need Y so we're down for your tile map but it is a thing you can do but anyway so if I'm in our walls tile actually I'll just I'll draw it I'll move that up here so if I'm within our walls tile and I start adding a few buildings so I'm just a new command shift-click building their building here building here let's make a little extension here you know just just some some buildings that we're adding and you know maybe there's a shed out back I don't know them something like this so I'm just adding some buildings they don't look great it kind of stands out there look weird but just to add something there Godot is not automatically gonna know that we should collide with these so I can just walk right over them I can shoot through them there's just no handling the collision so we need to fix that again notice that I'm not drawing these within the path of our enemies just trying to make sure that they don't get lost or stuck on a building but so in order to add collisions I'm going to come in to our tile set select our tile sheet again and select our wood building now we could add collisions to our grass and to our dirt and to our toaster but we definitely don't want to do it for a grass under there shouldn't be collisions there but we do want them on our wood building so if I select our wood building tile same before how we selected BIM mass and priority that's another thing to like I'll just real quick mention this say we did want to use all these single like tiles so notice that now we have four of these Auto tiles that all have the same bitmask well if you see here like all these tiles are one out of one because there's only one tile that matches that bitmask pattern but if we select here you'll see one out of four cuz Godot is realized oh there are four tiles that have the same bitmask pattern so I'm just gonna randomly choose out of those four but say we almost always wanted it to be the square one and we wanted these to happen you know very very infrequently we could change this priority here now that's not what we want I'm gonna get rid of these but just as an example that you can do that so let's get to collision and this is one of the more tedious parts of working with tile maps so I'm probably just gonna speed this up but I'll just show you real quick so in order to do collision you have to set it on a per tile basis and so I can do select create a new rectangle click this one here you can also do polygons instead of a rectangle but I'll just do a rectangle and I can just select on one of these one of these walls and just click and it will oops that's something I wanted to do I was selecting the wrong there we go so make sure you select your tile first your sub tile then I can click this and then just click and it'll automatically draw a rectangle that fills the whole shape and I can adjust these vertices as needed they're kind of limited by snap so you can you you usually want to keep this on this keeps your polygon inside your tile but if you turn this off this will turn off the grid snap so you can adjust these pixel or these pot or the Wow the vertices a little bit more fine-grained but for us it's good enough to just use the rectangle and here's the thing we don't actually care what each of these tiles are maybe we would eventually want this to be an interior and we would want the player to be able to walk like here so we would draw our collision shape you know something like this for now these are just strictly walls so we want whoops I need to redraw that but we just want this whole thing to collide with the player we don't want the player to walk anywhere here because these are this is just a wall so you'll see if I click out it'll be shaded yellow as a way of saying hey this tile has a collision shape whenever you go into collision and so what does it means is just going through and adding this collision shape to each one so luckily we just want our standard rectangle collision shape for each tile but we've got to manually go through that so I'm gonna click on this tile add a collision shape click on this tile click Add and then click on the tile I'm just going to go through and do this for each of these so kind of tedious I wish there was a better way to do it you can paste in like there are some fancy things you can do with like pasting collision shapes and pasting bit masks so for example like one thing you'll notice is that this like more orangish wood has the exact same tile set or exact same tiles as our wood building here so say that I had made our collision shape for this entire wood thing the wood building I believe there's a way yeah you can copy the bitmask create a new tile here and paste it on so you can save a lot of time doing that but I'm not sure there's a way to do that for collision shapes oops I accidentally made an extra one there so anyway all that say this is kind of tedious but it's just something you have to do so I'm gonna stop this here and just fast-forward and and finish adding our collision shape to all of these and then you should just do that on your own as well and then we'll move on from there okay so one thru and added collision shapes to all of our tiles and you'll notice I did not add them to the tiles we aren't using so no need to do work that won't matter and now if I run our game we will see that the player will collide with these buildings so we can't go past them which is awesome this is exactly what we wanted and it looks good and now we have collision and we could pretty much do this also to add an edge to our map so we can lock the player within a CERN within a certain area if we wanted to but yeah that's that's pretty much the way we add collision shapes to a game through I'll Maps now one thing you will notice though is that our bullet I can pass through and the reason for that if we come into our bullet script so open up below GD is we whenever our bullet enters a physics body which is happening so our bullet is colliding per se with our tilemap but because we are only destroying our bullet if that body that physics body it collides with has a handle hip method our bullets never getting destroyed it's just passing right through so I think what we want to do is just I'll shift tab to move our Q free so that our bullet whenever it collides with something it just gets destroyed I right now I don't think this is an issue if we were to add collision shapes to a bunch of other things that we didn't want our bullet to be destroyed on we'd have to add some extra logic here but for now this should be good enough so whenever the bullet actually collides with something we want it to to go away and because we're using an area 2d for our bases still won't clog that but now if I shoot our building it just gets destroyed which is great this is perfect it's exactly what we wanted and we've pretty much got working collisions within our game for a tile map so this is pretty much like all the major functionality for tile maps guys obviously there's a lot more we could do there's a lot of other stuff that would be cool we could add some other different types of areas like a little city or a market or a street or something tons of options I might actually do that in a upcoming videos just spend some time on my own to kind of build out the map and feel free to do that on your own too don't feel like you have to keep your map looking like mine you can add whatever you want to the game so if in the next video I've got a different looking tile map don't be surprised we'll see if that happens but otherwise guys I think this is pretty much if you have any questions about tile maps or other things you think would be cool to cover with tile maps let me know and I hope this has been a helpful introduction to tile maps and you feel comfortable and ready to use them in your own game now so thanks so much guys for watching always appreciate it if this was helpful I'd love if you like and subscribed to me and I'll see in the next video take care
Info
Channel: jmbiv
Views: 2,527
Rating: undefined out of 5
Keywords: godot, godot engine, godot 3.2, godot tutorial, godot top-down, godot 2d, top-down shooter, how to make a game in godot, game development, game development tutorial, game development for beginners, godot for beginners, how to make a top down game in godot, how to make a top down shooting game in godot, game dev, indie game dev, indie game development, how to make video games, how to godot, hobby game development, gamedev, godot game engine, godot tilemap, godot autotile
Id: sKfduY88CsE
Channel Id: undefined
Length: 42min 21sec (2541 seconds)
Published: Wed Jul 15 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.