Interactive Tilemap, with Tiles with different collision layers

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Coconut35

Sorry for my bad english.
I started working on a platformer, and I couldn’t find a way to make the player react differently depending on what type of tile he’s colliding with. I tried to use multiple tilemaps, so the player’s Area2D could recognize wich Tilemap entered it, but it’s pretty annoyning to constantly jump between tilemaps. Is there a way I could have all my tiles in a single tilemap, and still be able to know wich type of tile the player is colliding with ?

:bust_in_silhouette: Reply From: aeh_keine_ahnung

KidsCanCode has a nice tutorial about that:
Godot One Shot: TileMap Collisions

func _physics_process(delta):
for i in get_slide_count():
	var collision = get_slide_collision(i)
	if collision.collider is TileMap:
		#convert player position to tilemap coordinate
		var tile_pos=my_tilemap.world_to_map(global_position)
		#collision.normal is the direction of the colliding surface,
		#and can be changed to Vector3.DOWN
		#to only detect the tile the player is standing on
		#the index of the colliding tile
		#(can be seen when holding the ALT key in the tileset editor)
		var colliding_tile = my_tilemap.get_cellv(tile_pos)