0 votes

If I have a bullet, I want to get the tile name if it collides with any tile , anyone??

Godot version 3.2.3
in Engine by (385 points)

1 Answer

+2 votes
Best answer

You can't get the tile name. Tiles are identified by their index which you can view by holding down alt in the Tileset editor. Use the world_to_map() and get_cell() methods of the TileMap class.

Edit: As it turns out, you can get the tile name, but you have to get it from the Tileset's tile_get_name() method and not from the TileMap. You'll still have to get the index of the tile as well first.

by (7,792 points)
edited by

I'll see if I can pull all my related code - I get the Tile name all the time.
Sorry if this is messy - want to try to pull some code for you quickly...

var tilename0 = $map/TileMap.tileset.tilegetname($map/TileMap.get_cell(myposontilemap.x, myposontilemap.y))

if (npc.tilestandingon == "water" or npc.tilestandingon == "waterdeep" or npc.tilestandingon == "deepwater") and npc.doing != "swimming" and npc.doing != "standingInWater" and npc.doing != "drowning" and npc.doing != "coma" and npc.doing != "dead":
npc.doing = "standingInWater"

My NPC's run around the map and constantly look for what Tile they are standing on.
This seems to be the lines of code that do this for me. (Sorry, wrote over a year ago so not completely familiar with right now).

Huh, I didn't see that in the Tileset docs. Whoops! I'll edit my answer.

I just hope I understand the OP question properly.

In my game.... every tile counts.... SAND, MUD, ROCK, SKY, etc.
I seem to be able to pull the 'names'. Really have not looked at that area of the game for over a year.

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 webmaster@godotengine.org with your username.