Topic was automatically imported from the old Question2Answer platform.
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 ?
func _physics_process(delta):
move_and_slide(velocity)
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
tile_pos-=collision.normal
#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)