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

Question Big tiles give sort order problems in isometric game

Discussion in '2D' started by Wyxill, Aug 11, 2023.

  1. Wyxill

    Wyxill

    Joined:
    Oct 31, 2022
    Posts:
    3
    So, i have this 2 big tree walls sprites, 4 cells long and quite tall. The Character is high around 1.5 cells and large 1. For the walls i can set the walls pivot only in the first or in the last cell, cause i need this walls on a tilemap, and setting the pivot in the center of the cells will cause the wall to be disaligned (cause the pivot isn't in the center of a cell in this case). The character's pivot is on his feet.
    When the character is in front of the wall, all is ok. But when is behind the trees, this happens. The character pivot is now behind the wall pivot (that is in the center of the top cell of the wall), and the character pop un from behind the trees.
    What i can do for fix this? A solution would be to not use the "automatic" slicing of the atlas and trait all the 256*256 squares as different sprites... but would be a long work.
    Advices? Screenshot (688).png Screenshot (687).png Screenshot (686).png Screenshot (685).png
     
  2. venediklee

    venediklee

    Joined:
    Jul 24, 2017
    Posts:
    143
    Assuming the trees are actual gameobjects and not part of a tilemap
    You have two options:
    1. custom sorting:

    2. Multi sprite: (this is a bit hard to describe, so check the images)
      • Slice the large sprites into 2(or more, depends on the complexity)
      • Set the pivots of each side(this will usually be on the upper side of the 'base area')
      • Place the sprites on the scene
      • Set the sorting mode of sprite renderers to pivot
      • Adjust the positions of each gameobject to align the sprites
      • In the parent of these gameobjects, create a polygon collider 2D shaped like base area to prevent the dynamic objects entering the 'base area'. Don't forget the static rigidbody2d too
    in the end, dynamic gameobjects will be sorted correctly against large objects because they can't enter the physical base of them and they are sorted independently for each side.
    2023-08-11_21-37-40_AdobeExpress.gif
    sliced large texture and pivot point of each smaller sprite one:
    upload_2023-8-11_21-16-5.png

    Sprites are placed and aligned in the scene, with sorting mode: pivot
    upload_2023-8-11_21-26-43.png

    PS: if you need to sort one piece of the large object above the other piece, you can do it with sorting group component: https://docs.unity3d.com/Manual/class-SortingGroup.html
    I don't need to do that ever, because I use a custom outline: upload_2023-8-11_22-2-52.png
     
    Last edited: Aug 11, 2023
    Wyxill likes this.
  3. Wyxill

    Wyxill

    Joined:
    Oct 31, 2022
    Posts:
    3
    Sadly, the wall is in fact part of a tilemap, But maybe i can still use the second method?
     
  4. venediklee

    venediklee

    Joined:
    Jul 24, 2017
    Posts:
    143
    Trying wont hurt!! maybe look into the video's comments or other videos from the same channel

    Posting your findings(if any) here would be cool

    Cheers
     
    Wyxill likes this.
  5. Wyxill

    Wyxill

    Joined:
    Oct 31, 2022
    Posts:
    3
    Update: the first method, in the form of the demo project in the video description, dosn't work with tilemaps.
    The second method is ok (a 2-cells max long object will work fine with a character with pivot set on his feets ), but requires to slice all the long sprites.

    If someone have more advices, lemme know!
     
    Last edited: Aug 12, 2023
    venediklee likes this.