Search Unity

Custom sort order on top down game with diagonal objects?

Discussion in '2D' started by nicmarxp, Sep 3, 2020.

  1. nicmarxp

    nicmarxp

    Joined:
    Dec 3, 2017
    Posts:
    406
    I'm trying to figure out how to set up objects like the one in the video below. I have custom sorting order, and it's sorting by the pivot point, and this works well for most objects if they are square, horizontal or vertical. The problem is diagonal objects like the one here, when the player is on the top right edge and goes around.

    Is there any way to have the sorting order also be affected by the X-position of the comparing objects? Like use a different pivot point to sort when the player is on the upper right edge?

    Would this even work if multiple items are being sorted?

    My current solution is to make the collider so big that you can't end up in the position where you're in front of the ship, but still the player pivot point is higher.

    The yellow square shows the ship pivot point.

     
  2. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,511
    For situations like this, I slice my sprites in two or three so that there can be more than one pivot point then rely, like you, on colliders.
     
    nicmarxp likes this.
  3. nicmarxp

    nicmarxp

    Joined:
    Dec 3, 2017
    Posts:
    406
    Interesting, I will look into that :) just dont want it to look weird if things move through, like bullets and stuff :) thanks!
     
  4. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,511
    Curious, how did it work for your use case and what solution did you go with?
     
  5. nicmarxp

    nicmarxp

    Joined:
    Dec 3, 2017
    Posts:
    406
    Well, the current "solution" is to place these items in a corner, so I haven't really solved it, so I will see if it needs to be solved later, as we're making a demo at the moment :)