Is it possible to detect the type of tile your character has collided with?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By genete
:warning: Old Version Published before Godot 3 was released.

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?

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

genete | 2016-04-28 11:26

:bust_in_silhouette: Reply From: Hinsbart

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