How can I convert tile condinates into real world condinates??

Godot Version

4.3

Question

So I have a sprite 2d and have a 16 by 16 tilemap grid and I want the sprite2d to object to follow that grid but when I am actually doing it, then the sprite is not following wiht the cursor

Just multiply you coordinates vector by the size of your grid (16).

There’s a few things here:

  • `tilemap.local_to_map() needs the mouse position relative to the tilemap, not the global mouse position, unless they just happen to be the same
  • the coords you get from local_to_map() are tile coordinates; if you’re two tiles up and three tiles right, you’ll get 3, 2
  • there is a map_to_local() that turns tile coords into world coords, you’ll want that to position your sprite
  • you may have to correct by half a tile; I don’t recall whether tile_to_map() gives you tile centers or tile corners

THANK YOU VERY MUCH!! I have been stuck on this problem for like a day.Thank you bro