Tilemap Basics - Unity / 2021 (Tutorial)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome to my channel in this video i'm going to show you how to use unity's 2d tile map feature so first thing we'll want to do is have unity hub open go ahead and create a new project and i'm going to select a 2d project i'm going to call mind tile map tutorial and i'm going to find a good place to save it here and i'm going to go ahead and hit create and now that our scene is fully loaded i am going to go ahead and add in some folders that i always add in just to make things a little more organized for myself for this tutorial i am going to use this uh free asset called pixel art top down basic by knoss i'll leave a link to this down in the description if you want to use it as well with our art downloaded i'm going to drag the folder into our art folder i'm just going to use the art that they provided here in this texture folder and go ahead and choose sprite mode as multiple the filter mode to point no filter so that way our image doesn't look blurry when we use the tile map click apply in the sprite editor i can slice up this image by cell size so that looks like it makes a 4x4 if we use 64. i guess you can slice this up any way you want i'm going to do 32 by 32 just so i have a little more control over how things are going to look so i'm going to go ahead and hit apply and this pixels per unit value i'm going to change that to 32 because that's how i sliced up my individual images now to add a tile map i'm going to go over to my hierarchy right click 2d object tile map rectangular and i'm going to call this tile map ground and now to actually use the tile map we'll need to go to window 2d tile palette and that is going to add this tab to your screen the tile palette tab and we'll need to go ahead and create a new palette i'll call this level one i'll hit create and i'm going to look for a good place to save this i'm going to save it under my tiles folder and now to add your tiles here you can just select the image that we sliced up and drag it right into the tile palette and i'm going to save all of these in the tiles folder as well so now you can choose individual tiles that you want to be able to put in your scene let's go ahead and i'm going to draw out a little bit of a scene here to fill in a lot of squares at once you could use this rectangular tool and when you hold your mouse down and move your position it'll fill in all the boxes that you pass through in a square all right so we have a basic ground level established so now i'm going to add another layer on top of this so for our ground first thing i'm going to do is set the sorting layer i'm going to add a new sorting layer i'm going to call this ground i'm going to set our sorting layer to ground and then i'm going to right click on our grid in our hierarchy go to 2d object tile map rectangular and let's call this level trees you can see we have our trees file right here so i'm going to go ahead change this to multiple sprites in the filter mode to point no filter and i'll apply that and i'll go into our sprite editor and i'm going to do automatic slicing and i want our pivot to be at the bottom of all these sprites so now all of our slight sprites are automatically sliced out of this image and our pivots are right at the bottom and we can go ahead and hit apply and for pixels per unit i'm going to set it to 32 just so it's consistent with the other image that we had so now in our palette i'm going to go ahead and i'm going to drag in our trees and and i'm going to save it in our tiles folder as well so in order to add the trees to the correct layer we'll have to select our active tile map and we'll want to select trees and you can see our sorting is not quite correct at the moment so i'm going to sort that out first i think when i added our ground sorting there i need to move it up so it's the first thing that renders and now if i go back to our tile palette and i go to add our trees our trees are shown on top and you can just add a row of trees or be more selective than that and paste them wherever and you can see a small issue where the bottom of the tree is rendering on top of the top of the tree before it so clearly we don't want that so let's go back to our trees tile map and we can change our mode from chunk to individual and in order to fix this you'll want to go to edit project settings you'll get your project settings tab if you don't have it already go to graphics go to transparency sort mode go to custom axis set z to zero and y two one that will change it so things that are lower down in the y axis will render on top of things that are higher up on the y-axis depending on their pivot point so if you remember we set our pivot point on the trees to the bottom of the tree that way our rendering looks correct and i also added a little player character so if we go ahead and add them into the scene you can see they render on top of the bottom of the trees but if we go up they render underneath the leaves of the trees or behind the trees and for our tree lair if we were actually making a game we wouldn't want our player to be able to walk through the trees so we would go ahead and add a component called tiled map collider 2d and you can see that just adds colliders to all of our trees and i'm also going to add a composite collider 2d so that way we don't have over a bunch of overlapping meshes i want a rigid body to be set to static that gets added whenever you add a composite collider if you leave it how it was the trees will fall like they have gravity affected but if you change change them to static they'll stay in place and we want to check used by composite and now you can see we have a clean just one outline around the trees on that tile map instead of a bunch of overlapping stuff in the center if you don't like how the collider is fitting your tiles like for these trees there's a little bit of a space above you could go into your sprite editor go down to custom physics shape and select which tree you want to use or want to generate the physics shape for so i'm selecting this first tree and i'll hit generate and that is a really bad physics shape but up here you can see our tolerance so if i turn that all the way up to one you can see it fits pretty well but there's a ton of spaces or a ton of points for the collider so that's going to bring your performance down a lot so usually what i like to do is i get it to a somewhat decent shape if i don't like the default and then you can manually move these points to where you want them this is a little more time consuming though so if you're doing this just know it's going to take a lot of time and if you were to say update this image with new images that you'd have to slice up later when you go into your sprite editor and you go to slice if you have the method set on delete existing it could erase all the work that you put in for the custom physics shape so just keep that in mind and that is the basics for how to use the tile map system in unity i will be going further in depth with how to create rule tiles and different types of tiles for making your game development a little easier like if you didn't want to have to choose these individual path tiles a rule tile would just you draw the path and then depending on its neighbors each tile is determined what sprite it shows so i'm going to make another video going more in depth in that if you want to see that it should be linked at the end of this video or in a card somewhere or in the description thank you for watching if you like this video leave a comment down below or a like and tell me what tutorials i should do in the future thank you bye
Info
Channel: MichaelsGameLab
Views: 237
Rating: undefined out of 5
Keywords: unity, tutorial, tilemaps, unity 2d, tilemap colliders, tilemap sorting, sprite sorting, unity 2021 tilemap, composite collider, how to, game dev, game development, unity 3d, 2d, 3d, Top Down, layers, tilemap layers, sprite editor, slice sprites, tiles
Id: mDkjMNrQUio
Channel Id: undefined
Length: 12min 13sec (733 seconds)
Published: Sun Nov 07 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.