#Isometric Tilemap Not Placing Intuitively

3 messages · Page 1 of 1 (latest)

fringe aspen
#

I'm making a game where users place tiles from a tileset. My tiles are 16x32 (isometric) and the placement is not always how I would expect. When I am clicking on the side of an existing block, I want a new block placed on the side. When I am clicking on the top of a block, it should be placed on top. This seems impossible as my texture_origin is set to -8 to make sure it is at the top. In the first photo, you can see my mouse is in a grid cell, and a block is placed on top. But then if I hover over an edge, of course I would be in a new cell, and not placing next to the block edge. When I change the block's texture_origin back to -8 from 8, I get that problem but in reverse.

Essentially, a blocks position should be determined with other blocks, not just the grid. But I don't know how to do that.

rustic bridge
#

Quite a complex problem you got there. I will try my best to help.
Using the tilemap/ tilemaplayer's local_to_map() function, you can get the tile coordinates of the tile the player is clicking on.
Then using get_cell_tile_data() with those coordinates, you can get the specific tile the player clicked on.
If get_cell_tile_data() returns null, it should be empty.
Then using map_to_local() on the same coords, you should get the "center" of the tile (this ignores texture_origin).
If you have it set up such that the "center" of the tile is the visual corner of the tile, you can subtract the initial local position you clicked, you can get a Vector3, then based on the direction of this vector, you can decide if you clicked the "left side", "right side" or the "top side" of the tile.
Heavily simplified but I hope this helps.