I tried to do it
General rule of thumb when asking a question: if you already tried something, provide people with as much information as possible regarding what you've tried!
How i could convert my player's position to a tile index using worldtomap?
var cell = $TileMap.world_to_map($Player.global_position)
var tile_id = $TileMap.get_cellv(cell)
And how to check if the tile is free
if tile_id == -1:
print("free")
when the tilemap is flipped
Not sure what you mean here by flipped. Care to elaborate?
if not, move the character (along with its collision shape) to the nearest free space
Why would someone ever want to move a character without their collision shape? Respectively, why do you think that deserves a mention here? Also there is no such thing as one nearest free space in a grid - there are potentially up to four! Moving a character does not work differently when using a TileMap!