I have an isometric tilemap with tiles 32pixels tall and 64 wide. My cell size is setup as (1,0.5,1). I’m trying to get the tile clicked on by the user to highlight. I have tried constructing triangles and using trigonometry to do it, I’ve tried pixel height/width calculations, etc. I come close on the x-axis with constructing triangles, but y-axis is always wrong. Does anyone have some advice to help me? My camera is set at (0,0,-10) orthographic, size 5, near clipping .3, far is 1000. The further I move from origin, the more error creeps in. I also haven’t begun to account for -X axis tiles.
1 Answer
1It’s probably easier and more stable to raycast than do a lot of logic to try to work out where the tile is. You will need to add MeshColliders to the tiles.
RaycastHit hit;
if(Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit){
hit.collider.renderer.material.color = Color.red; //etc.
}
Thanks for the response. My tiles are not game objects. They're created at runtime in a script that generates the terrain. Won't having that many gameobjects cause performance issues? That's why I was going for the trigonometric calculations.
– pjslauta