0 votes

Okay, I've been pulling my hair out on this for a little while now. I need to try and pull a tile's ID that my player (a KinematicBody2D) is colliding with. I've been told that I can use get_collider_metadata() to pull said information, but I have no idea how to pull that off. Please help.

asked May 10, 2019 in Engine by 9BitStrider (169 points)

1 Answer

0 votes

Tiles do not have this. TileMaps work by batching all of the tile textures and collision polygons into one object.

When your KinematicBody2D collides with a TileMap, the collider that is returned is the TileMap itself. To detect what actual tile you collided with, you must translate the collision point to map coordinates, at which point you can retrieve the tile ID using get_cellv(). See the Tilemap and TileSet docs for details on the available methods.

You can also see a detailed tutorial on this here:

Or, if you prefer video:

answered May 10, 2019 by kidscancode (17,704 points)

This works perfectly. Thank you so much.

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 How to use this Q&A? before posting your first questions.