Search Unity

Isometric sort order not working when moving horizontally using the tricks I found in the forum

Discussion in '2D' started by tomzigza, May 18, 2020.

  1. tomzigza

    tomzigza

    Joined:
    Aug 4, 2017
    Posts:
    31
    I found the code from the community reps to get your camera to care about zorder as follows

    Code (CSharp):
    1. var camera = GetComponent<Camera>();
    2.     camera.transparencySortMode = TransparencySortMode.CustomAxis;
    3.     camera.transparencySortAxis = new Vector3(0.0f, 1.0f, zNumber);
    4.  
    5. #if UNITY_EDITOR
    6.     foreach (SceneView sv in SceneView.sceneViews)
    7.     {
    8.       sv.camera.transparencySortMode = TransparencySortMode.CustomAxis;
    9.       sv.camera.transparencySortAxis = new Vector3(0.0f, 1.0f, zNumber);
    10.     }
    Attached are images showing the problem. I am able to move my character along the bottom front side of the wall just fine (picture 1). However there is a spot on the back side where the character is behind the wall in reality, but the draw order has him in front of the wall(picture 2). If i move him a little further down the back side of the wall he gets fixed (picture 3)
    Thoughts?
    Spot1.png Don't mine the collider offset, I fixed this and its unrelated

    Spot2.png
    Spot3.png

    The setup is an Unity isometric tilemap set to use z and some tiles and a character sprite renderer combined with the above code to force the sort order to be iso friendly.
     
    Last edited: May 18, 2020