Why does `localToMap` incorrectly resolve the selected tile?

Godot Version

Godot v4.2.2 .NET

Question

Please find a GitHub repo with project files [here](https://github.com/b-commits/godot-sandbox/blob/master/TileMapHandler.cs).

Hey there,

I’m very new to game development, so please bear with me :+1:

I’m trying to make an isometric 2D game. I’ve added a TileMap node and set its tile size to 32x16 for the isometric perspective. Then I’ve created some 32x32 tile assets in Aseprite and imported them to Godot. I’ve also written some code which I was hoping would allow me to click on a tile and replace it with another tile. Line 35 is the most important here.

Now, for the most part it works okay, but it’s not very precise. E.g. if I click on the exact pixel at the tip of the red arrow, the block above with yellow elements will get replaced instead.

I tried playing around with texture origin and moving the tile map around, but it still doesn’t work as intended.

Any suggestions as to how to fix it would be much appreciated.

You can write your own localToMap method that fits your criteria

Edit: Your link is broken! can we see your tilemap and how it’s set up? Including what the tileset offset / yorigin looks like?

I resolved the issue yesterday before the mod approved the post.

Just needed to make sure the tiles are correctly aligned on the grid. The grid needed to be aligned with the top of the ‘cube’ and not be off-center. I adjusted it by tweaking the texture origin on the tile and making sure the TileMap does not have any transform set.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.