Tilemap Collision : How to place automatically collisions?

Godot 4.2.1

Hi erverybody !
I’m trying to create a racing game with a top-down view. I’m using Kenney’s Racing Pack for it. I’ve created a Tileset with Spritesheet but I’m having trouble with collisions. I’ve tried to place the collisions by hand, but it takes too long…
So I’m looking for a way to place the collisions automatically on the tile walls. But the walls aren’t whole tile so I don’t know how to do it…
Thanks in advance!

P.S : Excuse me if my english is bad, i’m french.

1 Like

When you click your TileMap, look to the bottom panel and select the TileSet tab.
Once that is open you need to “paint” your TileMap with different properties.

If you have not already, you need to add a new “Physics Layer” in the TileMap inspector. Once you have added that, you can go to the bottom panel and locate “Paint” tab. From there you can select the Physics Layer you just added from the drop down menu. Default shape is painting the whole tile, but you can customize the collision box to any shape that matches your tile.

The Painting method is great when all tiles have the same collision shape (by default the polygon is a full square/rectangle so it will work for all full tiles).

However, when dealing with different tile with different sprite shapes, you have to select each tile and apply Reset to default tile shape (shortcut F), which is OK but still takes time with many tiles. Plus you’ll have to spend extra time for fine tuning since generally collision shape is not 100% matching sprite appearance.

I should open a proposal to batch apply Reset to default tile shape to all tiles…

EDIT: Turns out Reset to default tile shape was NOT “Generate collision shape that fits sprite shape” it just always create a full rectangle. In fact, I found a way to batch Reset shapes on all tiles: you can multi-select tiles in TileSet > Select mode by using mouse drag. From here, properties are batch edited. So you can press F to Reset to default tile shape to all tiles.

But since Reset does the same thing for all tiles, it’s not as useful as I thought. What could help would be to add a “Generate collision shape that fits sprite shape” (Unity-style) feature.

I’ve written a plugin that can generate the collision polygons automatically. It can be found here.