0 votes

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: https://godotengine.org/qa/30967/signal-_on_body_enter-not-working-in-tileset

in Engine by (521 points)

1 Answer

+1 vote
Best answer

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.

by (21,531 points)
selected by

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!

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.

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 Frequently asked questions and 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 [email protected] with your username.