Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

clicks handle for isometric tile with high sptire

Discussion in '2D' started by MrMagister, Apr 8, 2019.

  1. MrMagister

    MrMagister

    Joined:
    Jan 8, 2019
    Posts:
    9
    Hi! I have a problem with click handle on Isometric tile when tile contain high sprite (some box, tree, or tower, etc). In general, only way I know how get some tile by clicking is using method WorldToCell with position from camera. But it not working for tiles with high sprite, because sprite cover more then one tile and if you click on the top of this tile's sprite you will get another tile.

    So, I would like to click on tile's sprite and get tile of this sprite.
    From example in picture bellow I would like to click in anywhere in red zone and get yellow tile and not tile with brown blocks.


    Can anyone help me with this?
     
  2. beanie4now

    beanie4now

    Joined:
    Apr 22, 2018
    Posts:
    311
    use WorldToCell with an offset of 1 on the Y. This will allow you to click the top of the tile not the bottom. (might be like .8 on the y or something just try it till its right)
     
  3. MrMagister

    MrMagister

    Joined:
    Jan 8, 2019
    Posts:
    9
    Not bad idea, but it will not works fully, becase as you can see on picture, red zone covers not only top cell, but half of right and left cells too.
     
  4. beanie4now

    beanie4now

    Joined:
    Apr 22, 2018
    Posts:
    311
    My solution works for clicking the tops of tiles, if you want the full red area then you will need a script to check if there is a tile below. If there isn't then pass that click to the adjacent tile.
     
  5. beanie4now

    beanie4now

    Joined:
    Apr 22, 2018
    Posts:
    311
    click.PNG

    So first we check if there is a tile below. Yes? Good we solved it.
    If not then like the right image we need to see what side of the square we clicked in. Depending on the sade we will gave the click to that tile.
    Lastly if there is no tile for either of those 2 then that means your clicking on the base of that tile and you can do that normally!
     
  6. MrMagister

    MrMagister

    Joined:
    Jan 8, 2019
    Posts:
    9
    See the image.
    Your first step to check "if there is a tile bellow" will be false in left example and from your logic then it wrong tile, but it not.
    In the second case from your example when you will click there, yellow tile will returned and I don't know how you would like to understand side of left block first of all because these blocks are just sprites.

    And I would like to find general solution for clicking on any form of sprite (tree, tower, etc) and blocks it's just an example.
     

    Attached Files:

  7. beanie4now

    beanie4now

    Joined:
    Apr 22, 2018
    Posts:
    311