Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Tilemap, sorting sprites

Discussion in '2D' started by oen432, Feb 10, 2019.

  1. oen432

    oen432

    Joined:
    Apr 24, 2015
    Posts:
    40
    Hi,

    Do you know the best way to create top-down 2D map (Tibia-like) with proper sorting?
    upload_2019-2-10_16-21-56.png
    This tree is placed on Tilemap grid. Player is of course separated object with Sprite Renderer.
    How should I make player render only over the trunk part which will have collisions?

    This is what I want
    upload_2019-2-10_16-27-57.png upload_2019-2-10_16-27-19.png
    Over the trunk and under the leaves.
    Should I write script for that or are there any components that could let me do that?
     

    Attached Files:

    Last edited: Feb 10, 2019
  2. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,533
    There are really two parts to the tree: the trunk and the leaves.

    And I think there are two issues. The first is sprite sorting. The second is: How tall is the tree supposed to be? The left image doesn't look correct to me. Is the tree really a short shrub? Is the player taller than the shrub? If not, the leaves should always should sort on top of the player no matter where the player is.

    If you want the leaves to always appear above the player, set it on a higher sorting layer.

    Otherwise, it might work to set the Transparent Sort Axis to (1,1,0). Here's Unity's tutorial: Sorting Groups and Transparency Sort Axis.

    If that doesn't fit your needs, this article by Breadcrumbs Interactive might be useful. I think it was written before Transparency Sort Axis was available. They discuss an alternate method and provide a little source code.
     
    oen432 likes this.
  3. oen432

    oen432

    Joined:
    Apr 24, 2015
    Posts:
    40
    Huh, had Post-Processing enabled so Transparency Sort Axis wasn't available, had to create new project. Setting axis to (0,1,0) works actually pretty well.