How does one get tile position of moving tilemap

:bust_in_silhouette: Reply From: njamster

The coordinates returned by map_to_world are relative to the origin of the TileMap, not relative to the Viewport. They are world-coordinates, not global coordinates.

This should work:

func left_pos() -> Vector2:
    var used_cells = get_used_cells()
    var result = to_global(map_to_world(used_cells[0]))
    return result

Hello there! I’m fresh new with gdscript, and I’m developing a roguelike while learning. I found this solution so useful while using a tilemap instead of a sprite for player movement in a grid, and get the global position of your player. Thanks!!!

joseanjim | 2021-01-31 18:47