How to collide every block in tilemap

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By daniel500013

Hi i have a small question. How i can detect every block separately in tilemap

i use c# in my scripts

here is my script whos i use but i must create new tile map to detect my lava or spikes as new collider to detect it. When i need those elements as one tilemap

:bust_in_silhouette: Reply From: kidscancode

I often find it’s easier to create multiple TileMaps for different types of objects. Think of it like layers in Photoshop - ground layer, hurt layer, items layer, etc. You can use the collision layer system to really simplify your code.

That said, if you want to detect what tile you’ve collided with, you take the collision position, convert it to tile coordinates (world_to_map()) and find the tile type with get_cell().

If you’d like to see an example of this in action, I’ve written a tutorial here:
http://kidscancode.org/godot_recipes/2d/tilemap_collision/