Get Tile on Tilemap

#1

I have a projectile (trigger) that collides with some tile. How do I get the TileID that was hit?

0 Likes

#2

You can get the position of the projectile within the script, which you can divide by the tile size to get the approximate position of the hit. floor it to get the nearest integer, and then use tilemap.get_tile to get the tile id that was hit.

1 Like

#3

Was thinking there would be a more direct way of doing it. I went ahead and did the division and tilemap.get_tile() however simply doing that is not enough, since the collision tile is adjacent to the projectile, not underneath it. I’ll account for the projectile’s velocity and do a check for the next tile in that direction.

EDIT eh, the directional thing isn’t working 100%. Not sure how to go about doing this.

0 Likes