# How do I convert screen coordinates to isometric tile map coordinates in libGDX using matrices

I know this has been asked many times but my question doesn't quite fit the others. I have an IsometricTiledMap and I need to get the tile under a set of screen X and Y coordinates. Here is a picture of my game: I need to get the tile that the player is standing on. I need to convert screen coordinates to isometric tile coordinates and the way that seemed the easiest was by using a matrix as described here: http://www.alcove-games.com/advanced-tutorials/isometric-tile-picking/#comment-56390

Unfortunately I have no idea how to change that code to fit a 128x64 tile instead of a 1.0x.5 tile. Here is my code

isoTransform = new Matrix4();
isoTransform.idt();
isoTransform.translate(0.0f, 32f, 0.0f);
isoTransform.scale((float) (Math.sqrt(2.0) / 2.0), (float) (Math.sqrt(2.0) / 4.0), 1.0f);
isoTransform.rotate(0.0f, 0.0f, 1.0f, -45.0f);

invIsotransform = new Matrix4(isoTransform.inv());

//touch vector
touch = new Vector3();

@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
touch.set(screenX, screenY, 0);
touch = gameCamera.unproject(touch);
touch.mul(invIsotransform);

pickedTileX = (int)touch.x / 64;
pickedTileY = (int)touch.y / 32;

debug(touch.x + " " +  touch.y);
debug(pickedTileX + " " + pickedTileY);

return false;
}


I think the problem is in this line isoTransform.scale((float) (Math.sqrt(2.0) / 2.0), (float) (Math.sqrt(2.0) / 4.0), 1.0f); but I'm not sure what to change.

• See this for translating coordinates: gamedev.stackexchange.com/questions/79108/… – bazola Jun 27 '15 at 13:50
• camera.unproject() is for converting pixel coordinates to game world coordinates. Not really the same as what I am trying to do. Unless you are saying that is why 0, 0 is in the wrong place in my game. Can you explain what you mean? – Vincent Williams Jun 27 '15 at 16:08

private Vector3 worldToIso(Vector3 point, int tileWidth, int tileHeight) {