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
  4. Dismiss Notice

Question Dynamic Sort order For walking in front and behind stuff

Discussion in '2D' started by vandel212, Apr 13, 2021.

  1. vandel212

    vandel212

    Joined:
    May 10, 2020
    Posts:
    24
    I'm using tile maps, and I'm having a difficult time with the concept of walking in front of things, and behind things and having the layers sort order show properly. Take the image below, I need it to behave like #1 & #2, so that if you walk behind it, you get that nice layering. However, I also need it to act like #2 when infront of it without looking like #3. Is there some sort of way to make the top of the barrels sort order change depending on if the player is in front of it, or behind it?

     
  2. rarac

    rarac

    Joined:
    Feb 14, 2021
    Posts:
    570
    put the pivot point of your character on the feet and then use transparency sort axis to sort by Y position
     
  3. ChrisDuhFir

    ChrisDuhFir

    Joined:
    Jan 11, 2013
    Posts:
    1
    This, and also make sure that the player and the top of the barrel are in the same sorting layer.
     
  4. vandel212

    vandel212

    Joined:
    May 10, 2020
    Posts:
    24
    Thank you very much, that seems to be a step in the right direction. I figured out that the tilemap rendering mode of chunk prevented this from working, and setting it to individual fixed that. However I'm running into an issue with things in the tilemap palette that are more than 1 tile tall. If I stand in front of it, it looks perfect. If I try walk behind it, I'll be behind the bottom tile, but in front of the other ones. like this:

     
  5. rarac

    rarac

    Joined:
    Feb 14, 2021
    Posts:
    570
    2options:

    1)dont use things that are more than 1 tile tall ( use game objects for that )

    or

    2) change pivot point of things that are more than 1 tile tall