How to get tile from Tilemap

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Cryingpants
:warning: Old Version Published before Godot 3 was released.

Hi I’m having a problem with Tilemaps, my tile has a script attached and I need to call a function, but I’m unable to get the tile I’m colliding with… is there any way to find it? I know I can find the type of tiles, but that’s not what I need.

:bust_in_silhouette: Reply From: Zylann

Tilemaps don’t support directly scripts on tiles. If you put a script in the tileset scene, it will be ignored. Whay you can do instead is to manually associate one script per tile ID (Names of the tiles can help), or replace the tilemap by a grid of actual nodes. But it depends on what you actually want, take a look at this discussion: More tools for tiles · Issue #5965 · godotengine/godot · GitHub

Btw if you need the tile you collided with, you could try to use the point of impact and convert it to tile coordinates with tilemap.world_to_map(pos).

Thank you for responding so fast!
Yeah I know I can get the tile coordiantes, but that didn’t help me much. I wanted some sorts of “interactive” tiles (like chests), well I guess I will have to take the long way around :smiley:
Thank you anyways

Cryingpants | 2016-07-30 17:50

IMO chests can be nodes, so you leave the tilemap for static elements :slight_smile:

Zylann | 2016-07-30 18:18

@cryingpants I am doing chests right now :slight_smile:

I just added a control node on the tilemap (not tilemap resource) and attached a script to it called Stash.gd and set some mouse_enter, mouse_out connections to show a little tooltip popup, and if the player clicked on the stash. I just placed this node ontop of the chest in the map, this way when a user clicks there, you should beable to interact with using zylann’s method upon clicking. (opening animation, etc)

wombatTurkey | 2016-07-30 18:30

That’s really clever, that might be the easiest solution of my problem.
And I think I can automate placing of the control nodes using script, so that won’t be as tedious as I thought.
Thanks for that suggestion :slight_smile:

Cryingpants | 2016-07-30 18:39