I'm seeking more of an advise here than a direct help.
I'm trying to create a 2d isometric terrain with multiple levels (faking height), like the one in OpenTTD. To accomplish that, I use multiple Tilemaps (one for each height level, with the appropriate y offset), which gives the desired result.
The main problem I have, is finding the tile under the cursor, which is important for various actions (e.g. terraform, place buildings etc.). The tricky part is that terrain tiles have slopes and they do not fit exactly in the isometric grid, so the classic method the Tilemap provides is not enough and needs adjustments.
So what I have tried so far is:
- first method, I looped (top to bottom) through the tilemaps, checked if the tile is occupied or not and did some corrections (due to slopes) accordingly - but there was always a gap that was not correctly handled and I was not willing to write a long tree of coord ifs.
- second method, I checked on which tile the cursor is over on the first level, checked on my heightmap for the corresponding level and tried to deal with the slope, but with the same result; there was always a gap.
- last method, I'm using Area2D with CollisionPolygon2D; when I place a tile on any Tilemap, I create an Area2D with a CollisionPolygon2D, that has the same shape as the sloped tile and is placed on the right coords to match the global place of the tile.
So, now everything works right, but with the cost of high CPU usage, that of course reflects to the FPS.
I can narrow the collision polygons enabled to the ones that are displayed each time in the viewport, but that is going to work only when zoomed, as when zoomed out the collision pollygons will be a lot. And I have not yet implemented any code to find the corner of each tile (needed for the terrafroming).
So, before continuing with that approach, I would like your advise: is this approach a good solution or is there something else I would try to find the tile (and each nearest corner) under the cursor?
Thanks in advance.