+2 votes

I have a TIleMap made according the using tilemaps documentation.
I would like to make my kinematicbody react differently if it collides with some kind of the tiles. For example I would like the kinematic body to bounce if it collides with its head the bottom of one type of tile, and land normally on the top if it collides with its feet. I can detect head and feet collision using the normal of the collision but I don't know how to detect the type of tile it has collided with, from the get_collider() method.

How can I detect the type of tile collided? Is that possible?

in Engine by (683 points)

I forgot to add tags to the question. Is it possible to add it later?
EDIT: Oh, yes, just edit the original question. :)

1 Answer

+3 votes

Sadly, TileMaps currently don't have metadata support for individual tiles.
There's a pull request for that, but it needs some more work.
So right now, you'll have to manually check for the tile index where the collision happened. Something like this:

#Constants for your tile indices as they appear in the TileMap. 
#First Tile is index 0

const TILE_FLOOR = 0
const TILE_WALL  = 1

#Later, when the collision happened (tilemap is your TileMap Node,
#coll_pos is the position of the collision)

var tile = tilemap.get_cellv(tilemap.world_to_map(coll_pos))
if tile == TILE_FLOOR:
    #Collision against floor tile
elif tile == TILE_WALL:
    #Collision against wall tile
by (924 points)
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 Frequently asked questions and 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 [email protected] with your username.