How can I get/make a tile ID for specific tiles in an autotile?

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

Hello! I’m building a simple platformer and have been using an autotile for my spikey walls and I’d like to have Area2D collisions only on the edge tiles. I’d like to add Area2Ds/CollisionShape2D to these tiles at runtime (or as a tool in editor). However, because I’m using an autotile, every tile has an ID of ‘0’ so I’m having trouble using a script to add Area2Ds (as per this question).

How can I loop through an autotile in GDScript and add Area2Ds only to specific tiles in my tileset? Or should I give up and use a manual tileset that’ll have IDs, or just continue adding CollisionShape2Ds manually?

:bust_in_silhouette: Reply From: dancaer69

I don’t know if this will help, because I don’t have much experience in godot, but I used tilemap in a project and I had similar problems to find which autotile was in a cell.
I solved by using of get_cell_autotile_coord(cell.x, cell.y), where cell.x,cell.y is the cell’s x,y values for the cell I wanted to find which autotile is there.
For example in cell(0,1) say that the autotile cords are (0,2), so this is the third autotile of the tile.
So maybe you can loop on tilemap cells and get all cells to get the autotile coords and then get only the cells which have the autotile in (0,2) coord.

I was looking back through my asked questions and forgot I even submitted this one! I had come up with a patchwork solution that used get_tile to check surrounding tiles in a sort of custom autotile. Your solution works much better, makes my code much cleaner, and saves me from several function calls per loop! Thanks!

arbo | 2021-05-08 15:43