Getting tiledata off a KinematicCollision2D

Godot Version

4.3 Dev 5


Given a collision between a player and a tilemap, how do I accurately query the tile I collided with?

I’ve been through several solutions and they’re all messy and sometimes inaccurate.

  1. I tried to access Shape, which is logically where this would be since the tilemap and the tileset is made of many shapes, as a body could be. But this is always null.

  2. So I settled to instead make this data a bit on the collision mask, and then raycast at the point of collision - the normal, for every bit i wanted to query. This is messy and as I add more metadata it wont be sustainable to be adding more and more bits reserved for these mechanics

  3. Then I moved to instead directly query the tiledata but this had its own issues, the margin of collision would place the coordinates on the tile above the collision, and then after correcting with the normal it can now be inaccurate if the normal is weird and offsets it into the next tile.

This can’t be the solution either, as getting tile data is per layer, and there is no way i can find, to get the layer i collided with.

Maybe I did not look in the correct places, but it feels weird that the docs tell me “heres how you put data on a thing you collide with.” but not how to properly get that data I collide with