Signal _on_body_enter() not working in tileset?

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

I’m trying to add spikes to my map and to do that I created a scene of the spike. This scene is an Area2D with an sprite and a colissionshape2D. I made with the body enter signal that when the player enters the spike, it prints “spike”. If I add the spike scene to my level, it works fine but if I convert the spike scene to a TileSet, the signal doesn’t work.

My problem is similar to this one but the solution that he found there doesn’t fit for me:

:bust_in_silhouette: Reply From: kidscancode

This is not how TileMaps work. A TileSet is a resource that contains only a limited amount of information per tile: texture, collision shape, navigation shape, and/or occlusion shape.

Don’t let the fact that you can use nodes as helpers to make a TileSet lead you to think of them as individual nodes. When using the TileMap, it is one object with a single texture (made up of all the tile textures added together), one collision shape (the combination of the individual tiles’ shapes), etc.

When you collide, you’re colliding with the TIleMap. Using the location of that collision, you can tell what type of tile you’re on.

I’m not sure if I got it very well…
So, to achive what I wan’t, I would need to use a method from the TileMap in order to get the type of tile that I’m on? If I’m right, what method would be?

Thanks for the help!

fpicoral | 2019-01-14 04:07

You should see the TileMap docs for all the available methods.

To find what your character’s tile coordinates are, use world_to_map(), which will give you the tile coordinates. Then, you can use get_cell() to find out what the tile in that position is. You’ll get a tile index (-1 if it’s empty). You can use that to pull data from the TileSet, such as name, etc. See TileSet for those details.

kidscancode | 2019-01-14 05:07