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

(here you can see the many tilemaps of a simple room, also visible are doors, navigation maps, and enemy containers)

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.

(the pit tilemap with Composite and Tilemap colliders, visible as green lines over the pit)

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.

(a secondary minimap camera that only sees the Map layer with its culling mask)

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

Buy Now$14.99 USD or more

Leave a comment

Log in with itch.io to leave a comment.