2D Multi-Layer Tilemap Design in Unity
In 2D game design, it is essential to have an organized and efficient way to determine how our tilemaps are designed and how they interact with each other. This can quickly become a debugging nightmare if you do not setup the appropriate rules, especially when the perspective is a slightly angled top-down like in Rogue Star Rescue. Today we'll discuss multi-tilemap strategies to minimize headaches and ensure realistic gameplay.
Tilemaps
The first thing you'll want to determine is how many tilemap layers you will have. This is important for both the rendering and the collision physics of the layer. In our game we prefabricate rooms, Here's an example of the tile layers we use for each room:
- Floor Tilemap
- Floor Overlay Tilemap
- Pit Tilemap
- AbovePlayerWall Tilemap
- DynamicWall Tilemap
- MidWallCollider Tilemap
- Map Tilemap
Floor and Floor Overlay Tilemaps
Conceptually these are simple layers. They both use a sorting layer called 'Floor' on their TilemapRenderers. The Floor tilemap has a sorting order of 0 and the overlay tilemap has a sorting order greater than 0. This ensures that everything on the overlay layer is always above the floor. In this example the stripes around the pit are on the overlay layer. These tilemaps don't have any colliders since the player and enemy walk freely on top of them.
Pit Tilemap
The pit tilemap is similar to the floor in that it is always rendered below the player. It is on the same sorting layer (Floor) and has the same sorting order (0). The main difference is that this layer uses colliders as triggers, to detect when a player or enemy falls in a pit. This requires a TilemapCollider2D component. We also use this with a CompositeCollider2D to combine and decrease the number of collider vertices, this is important for performance.
AbovePlayerWall and DynamicWall Tilemaps
These are two sets of tile maps that only differ by their sorting layer. The AbovePlayer map is on a sorting layer called "AbovePlayer" and the DynamicWall map is on a layer called "Dynamic". In many cases, you may be able to combine these into a single wall tilemap. However, we found this was better for cases where the player is rubbing up against walls. The sorting for the overlapping gun looks more realistic. The Dynamic sorting layer is what most characters and gameplay objects are on. It uses axis dependent sorting to determine what goes on top of what. We will discuss sorting in more detail in a future article. These tilemaps also have composite colliders to restrict the movement of the player and enemies;
MidWallCollider Tilemap
This map won't apply to everyone. It's a tilemap without a renderer that is derived from the wall tilemaps programmatically. Essentially it copies the structure of the wall tilemaps and offsets the collider by roughly half a tile. This is put on its own collision layer (do not confuse with sorting layer) that bullets interact with. This allows bullets to collide with the center of the wall instead of the base of the wall where the player's feet collide. The collision rules used in each game are different so it's up to you to determine what the most efficient way of dealing with this is. It can get a bit tricky in 2-D games where you essentially have to fake a third dimension (height).
Map TileMap
This is a tilemap on its own collision layer "Map" even though it does not collide with anything. Its sole purpose is to create what is shown on the minimap. This is done by using a secondary camera that only sees the collision layer "Map" on its culling mask. This tilemap is derived by combining the others. Copy all the floor tiles and wall tiles to it, optionally you can include the pits if you want them in your minimap.
That's the basic structure we use for rooms and hallways in Rogue Star Rescue. Each game will be different but hopefully, that gives you some insight on how to structure your game's many tilemaps.
Get Rogue Star Rescue
Rogue Star Rescue
A unique mix of bullet hell roguelite shooters and tower defense games.
Status | In development |
Author | chuteapps |
Genre | Action, Shooter |
Tags | Bullet Hell, Co-op, pixel, Retro, Roguelike, Roguelite, Sci-fi, Top-Down, tower-denfense |
Languages | German, English, Spanish; Castilian, French, Italian, Japanese, Portuguese (Brazil), Russian, Chinese |
More posts
- Tower Defense Survival Mode!Mar 25, 2021
- Major Update V1.2.0. RAMPAGE Mode!Mar 18, 2021
- New Trap Perks!Feb 16, 2021
- V1.0 is now released and out of Early Access!Feb 04, 2021
- Major Update V0.49!Dec 18, 2020
- Major Update V0.48!Nov 24, 2020
- Major Update V0.47!Nov 07, 2020
- Major Update V0.46!Oct 21, 2020
- Major Update V0.45!Oct 07, 2020
- Major Update V0.44!Sep 25, 2020
Leave a comment
Log in with itch.io to leave a comment.