# Game Maker - Selecting tiles in an isometric grid

I have implemented an isometric grid with rotation in 2 directions in Game Maker. I did this by first calculating the points of the grid in 3D space and then converting them to 2D points through equations I derived from rotation matrices. I use a single object to draw the grid, and would like to be able to click on a tile to select it.

Here are the equations I use to convert the initial 3D points (x, y, z) to isometric 2D points (iso_x, iso_y), where b and a are the angles I'm rotating the grid by:

iso_x = cos_b * x - sin_b * y
iso_y = cos_a * sin_b * x + cos_a * cos_b * y + sin_a * z


I attempted to rework the equations to calculate the tile from mouse coordinates, but I've run into the problem where I have 2 knowns (mouse_x, mouse_y) and 3 unknowns (x, y, z), which will make implementing height difficult.

So I guess I'm looking for suggestions on how to do tile picking better, especially when it comes to choosing tiles with height. If you need extra information, I will try to provide it.

I want to keep the rotations, so moving to sprite-based tiles probably won't work because the shape of the tiles will change as the grid rotates.

• The 2 knowns / 3 unknowns mismatch means your solution is a line: a ray traveling through tile space. Instead of a single intersection, you have a family of potential intersections depending on the heights of tiles in your game map (collectively, the third known). You can raycast or march along this ray, one tile at a time, until you hit the first height at which the tile it passes through is non-empty. – DMGregory May 17 '20 at 8:26
• @DMGregory I assume this line runs from the camera through the screen, similar to picking objects in a 3D environment. But I'm using a 2D environment, how would I get the camera position? Or do you think I could get an isometric appearance using something like 3D blocks with an orthographic projection rather than a perspective projection? – user137 May 17 '20 at 8:34
• You already have a 3D world, you're just doing the 3D to 2D projection manually. It's still the same math we use in 3D transformation with an orthographic matrix. That means you do have a camera viewpoint, it's just implicit in your math rather than explicitly stated. – DMGregory May 17 '20 at 8:38