Search Unity

Dynamic Drawing !!!Pls Help!!!

Discussion in '2D' started by SAVVU, Feb 7, 2016.

  1. SAVVU

    SAVVU

    Joined:
    Dec 6, 2015
    Posts:
    21
    I just came across this post:
    http://forum.unity3d.com/threads/dynamic-draw-order-or-2d-z-buffer.220231/#post-1475523

    As I am now srtuggling with a same kind of problem with my 2D Project I would like to ask a question:
    In my Scene are 2 Monsters(Sprites) and Both have many children(Even the children have children)..
    So I would like to have the Monster that has a lower Y value infront of the Monster with the higher Y value.
    I tried out this code but unfortunally each Monsters Sptites were messed up..I also read something about the z value but didnt know exactly what it was about!
    This code I tried out putting on each children Sprite: tempRend.sortingOrder = (int)transform.position.y * -1;

    Thanks in advance!!
    Cant wait to hear an answer..Greetings
     
  2. Hyblademin

    Hyblademin

    Joined:
    Oct 14, 2013
    Posts:
    725
    Are you also making a 2D iso game? I feel like updating the z position as a function of the y position should do it. In fact, just setting transform.position.z equal to transform.position.y each frame should do exactly what you want, yes? This doesn't take into account max draw distances for cameras and possibly min/max depth for things like raycasts, but you can get around that by setting z as 1/10*y or something instead.
     
  3. ColossalPaul

    ColossalPaul

    Unity Technologies

    Joined:
    May 1, 2013
    Posts:
    174
    Hi, SpritesRenderer does not update the z-buffer hence it is important to use SortingLayer and orderInLayer. This area of the code is sorely lacking support for isometric character type games like you are developing. Feel free to share with us your difficulties.
     
  4. SAVVU

    SAVVU

    Joined:
    Dec 6, 2015
    Posts:
    21
    Thanks for your replies!!
    I managed to solve this by having all my my Sprites (Including children ) on the same Sorting layer and sorting order = 0!
    The code that increases the sorting order looks like this:
    tempRend.sortingOrder = (int)transform.position.y * -1000;
    As a result each child will b rendered on the right position even of the y values are very close...thats why I multiplay with 1000 to get even 3 digits after the comma!
     
  5. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Yep, I do something very similar to that (though I only multiply by 100), and it's working fine for me.