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.

in Engine by (197 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:

by (20,483 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.
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.