# Mouse position to Isometric Grid Tile number

I am trying to use a mouse position to find a grid location (column / row). Can anyone help me write a few lines of code to make this happen?

The grid starts at world position (0,0) and stretches downwards and out. The maximum number of rows is 61 and the maximum number of columns is also 61. The entire grid is stored in a single dimension array. Indexes 0 through 60 represent row 0, columns 0 - 60. Index 61 would mean row 1, column 0. See photo here: 1

The tiles are 4 units in height and 8 units in width.

Is there any good reason why you arranged your squares at 45°? You should just arrange them paralell to the world axes and place the camera rotated at the desired position.

The coordinates are just the world position divided by the tile size. One tile is 4x4 so if you use the Plane class for example to get the world position of your click, just divide it by 4 and "round down" / "truncate the number" / "cast to int" to get the index value.

You should really rephrase your question since this is a Q&A site, not a free-script-shop.

Here's a small code snippet how to get the world position of the mouse on a Plane:

``````//C#
// Define your ground plane by create an Plane instance with your plane coordinates / normal
Plane myPlane;

Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
float distance;
if (myPlane.Raycast(ray,out distance))
{
Vector3 pos = ray.GetPoint(distance);
int xIndex = (int)(pos.x / 4);
int yIndex = (int)(pos.y / 4);
int index = yIndex*61 + xIndex;
// Do something
}

``````

You had negative numbers in your image so keep in mind that you might need to invert one number first.

If your ground plane goes through (0,0,0) and is facing upwards just create the plane like this:

``````Plane myPlane = new Plane(Vector.up,Vector.zero);

``````

The first parameter is the normal vector, the second a point on the plane.