- Home /
How do I add collider to tilemaps?
I'm making a procedurally generated top-down 2D game. How do I add colliders to the tilemap so that my player can't go trough walls.
Here's the code that generates the tiles:
tileMap.SetTile(new Vector3Int(x, y, 0), groundTile); tileMap.SetColliderType(new Vector3Int(x, y, 0), Tile.ColliderType.Sprite);
Judging by your code you snippet you only want to have a specific tile have a collider, in this instance I'd use a rule tile and have the collisions set up from that. If you want all of the tile map to have a collider use you can add the component Tilemap Collider to the Tilemap object. Hope this helps.
$$anonymous$$anaged to make it work using rigidbody 2D.
Answer by CaptainAk2310 · May 26, 2020 at 04:17 PM
Its been two years, I dont you got the answer for it or not. But I was also searching for same and found my answer in "Tilemap Collider 2D " component.
Answer by DiaryChris · Jan 23, 2019 at 01:30 AM
Add the component Tilemap Collider 2D to the Tilemap object. Then change the ColliderType of all tiles to None, and change the ColliderType of specific tile to Grid by code ,I have encountered the same problem. Do you have a solution?
Your answer
