The game I'm making is a 2d platformer which you should be able to destroy tiles as you get close to them (something like terraria), to do it I implemented a raycast2d to detect which tile (using tilemaplayer, not tilemap, this may be important) the player is colliding with. This is my code (but it passed through several changes and versions)

if Input.is_action_just_pressed("mine"):
if rc.is_colliding():
var l = rc.get_collision_point()
var cell:Vector2i = tmpi.local_to_map(l)
var data = tmpi.get_cell_tile_data(cell)
print(data)
else:
print("nada")

what is printed in data is "object null" but var cell it shows correctly the tile position. In other of my tests I used get_atlas_cords, also returned to -1,-1 meaning its null
just showing the big picture because maybe I'm doing the whole thing wrong... and because I'm stuck in this for 3 days
pls help

  • xyz replied to this.

    bergsonson Print the cell coordinates and determine if they correspond to the correct cell.

      bergsonson The method of looking with your eyes 🙂
      Prior to start, write down at which cell coordinates is that first cell the character is facing. Start the game, approach this cell and see if printed cell coordinates match what you've written.

      weird, when I open the tilemaplayer its coords be 5,4 but when I run the game it prints var cell (24,22)

      • xyz replied to this.

        bergsonson That can only mean one thing - local_to_map() is not getting its position argument in tilemap's local coordinate space, which it expects.

          xyz
          God! I found out what happened. When I was creating the tilemap I scaled up the tilemaplayer node to fit better in screen, this messed up the local_to_map function, something I could NEVER guess...
          Newbie things I guess
          Thanksss! 😃

          • xyz replied to this.

            bergsonson You can still live with scaled or otherwise transformed tilemap (or any of its parent nodes). Just need to transform the position to tilemap's local space. Since raycast result is in global space you can do: var l = tmpi.to_local(rc.get_collision_point())