Search Unity

Need help to sort sprites

Discussion in '2D' started by Bergamotte, Feb 23, 2021.

  1. Bergamotte

    Bergamotte

    Joined:
    Oct 28, 2019
    Posts:
    6
    Hello, I want to implement some jump mecanic to my 2D top down game, and so add heights. I have set the transparency sort axis to 0x, 1y, -1z (-1 to have the sprite with a higher Z to be above) as to have the sprites sort on their Y and their Z axis, to somehow have a fake 3D. Everything seems to go well but not for the floor :/. I have to make unity thinks it's flat somehow, or remove the sort axis by Y to only have Z for this ? But I don't know how to do that (You can see the video to see the problem).


    I hope I was clear enough.
    Thanks in advance for any help !
     
  2. rarac

    rarac

    Joined:
    Feb 14, 2021
    Posts:
    570
    increase the z of the tiles that have higher y

    grass tile y = 1 should have z =1, y=2 z=2
     
  3. Bergamotte

    Bergamotte

    Joined:
    Oct 28, 2019
    Posts:
    6
    I tried it and the problem is still the same
     

    Attached Files:

  4. rarac

    rarac

    Joined:
    Feb 14, 2021
    Posts:
    570
    you should set your sorting axis to 0,0, z = 1/-1

    change your scene view to 3d so you can see how things are sorted

    of course your character must follow the same rules as the tile

    change the char z when he walks up on the y axis

    when jumping use only the y axis, dont touch the z
     
  5. Bergamotte

    Bergamotte

    Joined:
    Oct 28, 2019
    Posts:
    6
    It seems to work well from what I tested, so thanks a lot !
     
    rarac likes this.
  6. Bergamotte

    Bergamotte

    Joined:
    Oct 28, 2019
    Posts:
    6
    Welp, I just went on my project again, and by trying to fix my code to adapt it to this new sorting way, I discover that I still have the same problem at the start :/. I guess I would have to sort the floor pixel per pixel and not the whole sprite, but I don't know how to do this.
     
  7. rarac

    rarac

    Joined:
    Feb 14, 2021
    Posts:
    570
    i am making a game that uses the same system that you are trying to do in your picture and i got it working after many months of coding, but its so much code that is hard to teach you how to do this just on a forum and would spend too much time sorry =x

    the most that i can tell you is that you have to create a fake terrain of blocks
    the grass will be on height 0, and when your character stands on the grass he is 1 block above the grass so his height is 1.

    since the grass coord would be (0,0,0) and the character on top of grass would be (0,0,1)
    then you make the calculation for true world position y-z, the vector3 pos of your char would be (0,0,-1) which will make him above grass.

    In 3d scene view when your character moves up on y axis he will be moving diagonally on z axis, because for every object and tile you must make z = y+height
     
    Last edited: Mar 6, 2021
  8. Bergamotte

    Bergamotte

    Joined:
    Oct 28, 2019
    Posts:
    6
    But isn't there a way to render it how I want by having the character only one pixel unit (0.0625 I think) instead of a full block ?
     
  9. rarac

    rarac

    Joined:
    Feb 14, 2021
    Posts:
    570
    only if you are crazy enough to make each of your tiles the size of 1 pixel, and draw your map pixel by pixel on that tilemap ( the cpu cost of this will probably be massive )
     
  10. Bergamotte

    Bergamotte

    Joined:
    Oct 28, 2019
    Posts:
    6
    Oh right it's going to destroy my cpu if I do that x)
    Well I'll make it go always one block above so, thanks for helping me through this !