Search Unity

[Isometric Tilemap Z as Y][Camera][Mouse] Correct way of handling mouse events

Discussion in 'Scripting' started by Kondix, Oct 20, 2019.

  1. Kondix

    Kondix

    Joined:
    Dec 23, 2018
    Posts:
    1
    Hello good people,

    I'm developing isometric game, basing on Unity tutorials and my personal experience.
    Right now I'd like to handle Mouse Events on my Isometric Tilemap Z as Y.

    Idea is very simple, whenever mouse is over tilemap, get cursor position and paint given tile red. Sounds very simple, but I've encountered a major problem. There is no way of getting correct coordinates.

    I tried this code in Tilemap's OnMouseOver method:

    Code (CSharp):
    1.  
    2.         var clickPoint = Camera.main.ScreenToWorldPoint(Input.mousePosition);
    3.  
    4.         var localPoint = tileMap.LocalToCell(clickPoint);
    5.  
    6.         if (tileMap.HasTile(localPoint))
    7.         {
    8.             Debug.Log("Tilemap has tile");
    9.         }
    10.  
    I'm unable to retrive any tile.

    The first issue is localPoint.z always set to -10. So I created tile position to tile height map which also didnt help much - it seems all points are shifted in x and y axis.

    Here is how my Isometric Tilemap Z as Y looks like:
    upload_2019-10-20_13-58-20.png

    Tiles have different z values (1 step is z+1).

    Do you guys have some valid ways of handling mouse events on Isometric Tilemap Z as Y?
    I'd realy appreceate some help.