Different collision layers/masks for each tile type in Tilemap

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By tomajar
:warning: Old Version Published before Godot 3 was released.

I have a project setup with 2 different tiles. Tile A’s StaticBody2D has a collision layer/mask of 0b01… and Tile B has a collision layer/mask of 0b10…
However when I export that scene to a Tileset and import the Tileset into another scene, both tiles seem to use the collision layer/mask of the Tilemap.
Is there a way to have different types of tiles in one tilemap have different collision properties?

:bust_in_silhouette: Reply From: eons

The tilemap is a simple structure, optimized for drawing, collisions and navigation, tiles are just resources that have texture, shape (if solid) and navigation maps (and a few things more, like occlusion shapes).

It have only one single set of collision layers, to do what you want, you will need a second tilemap on another layer.

I came to this conclusion as well. I found a work around by looking at a Tilemap’s individual tiles for each level, and then loading up collision layer/mask for the tile type and then placing a non-visible tile on a separate Tilemap. Each Tilemap corresponds to a collision layer/mask. I do not intend to have more than 5 layers.
This allows quick designing of a level with a single Tilemap while still granting the flexibility of having seprate collision layers on a tile type basis.

tomajar | 2017-08-08 12:29

I had the same problem, and I find your solution very interesting. Could you explain a bit more precisely how it works ?

Coconut35 | 2023-02-02 11:38

Just use the tilemap node as a layer,

Level
|-TilemapLayer1
|-TilemapLayer2
|-TilemapLayer3

That is a useful way to control active parts (like having several floors overlapped), lighting, etc.

Godot 4 adds a bit more complexity to the tilesets which allows to create several physical layers per tileset, this could make it a bit harder to set up but requires less work in scenes.

eons | 2023-02-02 23:01

But how do you “look at a Tilemap’s individual tiles” for and load up the corresponding collision layer ? Do I have to use a dictionary with keys for each tile, or something like that ?

Coconut35 | 2023-02-04 07:50