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

Isometric Tilemap - Get top sprite

Discussion in '2D' started by loconeko73, Sep 4, 2020.

  1. loconeko73

    loconeko73

    Joined:
    Aug 13, 2020
    Posts:
    17
    Hi everyone,

    A bit of a Unity beginner here. I have what I thought would be a simple question, but it turns out not to be.

    I have an isometric Tilemap, each tile contains one or more GameObjects with a sprite showing floors and walls. In order to detect a click on a specific Gameobject, it's rather easy when there's only a floor. I would not even need a ray cast for that, as the Tilemap gives me all the coords transform that I need.

    But when clicking on a wall, the wall's sprite could be partially hiding its own tile's floor or even a neighbouring tile's. So I created PolygonCollider2D to raycast, but the problem is the Colliders are all over the place and the one on top is not necessarily what is visually on top.

    screenshot001.png

    I have searched a lot and spent a lot of time but I have yet to come up with a good solution. I'm almost thinking that the most straight forward way of doing this would be to create an off-screen representation of my Tilemap with a unique colour assigned to each object, paint that based on rendering layers (knowing which object is on top : a problem I have already resolved), then compare the pixel clicked to that off-screen image.

    It sounds hacky, but neither simple arithmetic nor ray casting have given me what I need.

    If there's a solution out there that knows how to identify the object of a specific sprite based on a click, I'm all ears.

    Thanks in advance !
     
    Last edited: Sep 6, 2020