How do I get what tile the 'player' is colliding with?

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

I have a 2D kinematic body named “spider” and a TileMap in the same scene. I want the player to ‘die’ when on a certain tile.

The code I tried for this is mostly attempts at using world_to_map and get_cellv, and whenever it runs I just get -1 or (0, 0), so I’m left confused. I’m still quite new to Godot and can’t get it working at all, so any help would be appreciated.

code on a 2D node:
var posx = player.position.x
var posy = player.position.y
print(map.world_to_map(Vector2(posx, posy))) – output: (0, 0)

:bust_in_silhouette: Reply From: dustin

im not sure how to do what you want exactly how you think you want to do it, but you can easily think of a workaround.

example: seperate the deadly tileset with the non-deadly tileset (in the same scene). this gives flexibility when your checking for collision. say, name the deadly tileset is “die” and the safe one “normal”. then, when you check for collision, get the colliders name and if the name of the collider is “die”,call your playerdeath function. this is a relatively simple workaround, but it should work more or less.