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

Tile Map sorting problems

Discussion in '2D' started by Jere_97, Jan 23, 2018.

  1. Jere_97

    Jere_97

    Joined:
    Aug 17, 2017
    Posts:
    4
    I'll be short... My level is a tile map, and the player gets rendered behind the plants and grass or on top. is there a way for the player to get rendered behind if its, for example, in the upper half of a tile or something like that?

    I want to implement this on the next GGJ in a few days, so any sugestion will be really apreciated.

    Thanks for the help and sorry for the redaction, i don't speak english.
     
  2. mvriel

    mvriel

    Joined:
    Mar 17, 2015
    Posts:
    13
    What you could do is, if you know the height of your tile you could change the player's z position, or sorting order, based on whether its y position is higher than the base of the tile + half the height of the tile.
     
  3. Jere_97

    Jere_97

    Joined:
    Aug 17, 2017
    Posts:
    4
    Hi mvriel, thanks for the answer. That can work but in specific cases.

    If i have two tiles, one in the upper position of the other, and the player its standing in the upper half of the bottom tile it should be rendered behind that one and in top of the other, at the same time.

    You have given me an idea, maybe i can change the individual z position of every row of tiles and get the desired effect.
     
  4. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,802
  5. Jere_97

    Jere_97

    Joined:
    Aug 17, 2017
    Posts:
    4
  6. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,802
    Yes, that is the expected behavior -- sorting per renderer. You can use the prefab brush or gameobject brush to place additional objects into the grid as separate SpriteRenderers, or place them by hand as children of the grid. Then your objects will sort separately. Single objects made of multiple renderers can use the SortingGroup component on the root object to sort as one object.

    You can also create custom Tiles that spawn prefabs into the grid on StartUp, to preserve the tile-only approach.
     
    Jere_97 likes this.
  7. Jere_97

    Jere_97

    Joined:
    Aug 17, 2017
    Posts:
    4
    Looks like that is the way of do it, thanks. :)
     
    LiterallyJeff likes this.