+1 vote

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?

Godot version 3.2.3
in Engine by (25 points)

1 Answer

+1 vote
Best answer

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 getcellautotile_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.

by (219 points)
selected by

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!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.