How to add collision to a Godot TileMapLayer (and an AI that did it in 2 minutes)
This post is the collision section of our full guide, Godot TileMapLayer Tutorial: Setup & Example Project, where you can download the example project used below.
Add collision to a TileMapLayer
A TileMapLayer has no collision until its TileSet has a physics layer and the solid tiles have collision polygons.
The steps, from the official TileSet tutorial:
- Select the
TileMapLayer, click itsTileSetproperty in the inspector, unfold Physics Layers and choose Add Element. - Open the
TileSeteditor at the bottom, select a solid tile and open its Physics Layer 0 section. PressFfor a full-tile rectangle, or draw a polygon. - Repeat for every solid tile. Tiles without a polygon stay walk-through, which is what you want for water or decoration.
- Leave Collision Enabled on in the layer's inspector, and check that your player's collision mask includes the physics layer's collision layer (both default to layer 1).
ChatGPT and older tutorials often describe the deprecated TileMap node instead. A forum user adding collision put it plainly: "Even ChatGPT cant help me, because he only knows the old TileMap" (Godot Forum).
Tested: an AI adding collision to this example
We gave Ziva, an AI agent that runs inside the Godot editor, this page's downloadable example with this request: add collision to the Ground layer so a player can stand on the grass and stone tiles, keep the water tiles non-solid, add a CharacterBody2D player with gravity and arrow-key movement, and check that it lands instead of falling through.
What it did, from the run's tool log:
- Read the
TileSetwith itsTileMapLayertools: one atlas source with four tiles and no physics layers. It found thatdemo.gdpaints the cells at runtime, so the saved layer has no tiles. - Read the tile art to tell grass, stone, water and gold apart, then called its
TileSetatlas tool with collision shapes turned on. The tool added the physics layer but skipped the shapes because the tiles already existed, while still reporting success. Ziva caught that by reading the scene file and added 16 x 16 collision polygons to grass and stone only. We have filed that tool behavior as a bug. - Wrote
player.gdand added the Player node. Godot's GDScript checker reported no problems. - Ran its physics validator (the player's mask matches the tile layer) and then the scene. The player landed on a tile under the gold marker, so Ziva moved the spawn to plain grass and checked the result in code: resting on the grass, grass and stone with one polygon each, water and gold with none.
It took 2 minutes, 23 tool calls and $0.03 of Ziva usage on Ziva Smart, the default model.
Our own check, a separate script run on the result, agreed: the player came to rest on the grass row, with grass and stone solid and water and gold without collision. In this map the water sits below the grass row, so the run shows the water has no collision shape rather than the player falling into it.
Ziva.sh makes Ziva and wrote this test. We ran it on 10 November 2026 with Godot 4.7.2 on Linux and a development build of Ziva. It is one project and one run, so treat it as an example, not a benchmark.
For procedural maps the same agent can write the set_cell(coords, source_id, atlas_coords) loops; every cell is reachable from GDScript.
If the player still falls through after this, see our collision checklist. For the art that feeds the TileSet, see our pixel art guide, or generate tiles with AI inside Godot.
FAQ
How do I add collision to a TileMapLayer in Godot 4?
Select the TileMapLayer, edit its TileSet in the inspector, unfold Physics Layers and choose Add Element. Then open the TileSet editor, select each solid tile and draw its collision polygon (press F for a full-tile rectangle). Leave the layer's collision enabled, and make sure your player's collision mask includes the physics layer's collision layer.
Can an AI add collision to a Godot TileMapLayer?
We tested Ziva, an AI agent inside the Godot editor, on this page's example project. Asked to make the grass and stone tiles solid and add a player, it added a physics layer and full-tile collision polygons to those two tiles only, wrote the player script, checked the layers with its physics validator and ran the scene. The player landed on the grass. It took 2 minutes and $0.03 of Ziva usage on the default model. One of its TileSet tools silently skipped the collision shapes, and Ziva noticed by reading the scene file.
Comments
No comments yet. Start the discussion.