Search Unity

Question Is it possible to have Rule Tiles change their rendering layer depending on what tile it is?

Discussion in '2D' started by Wigglepuff, Dec 2, 2022.

  1. Wigglepuff

    Wigglepuff

    Joined:
    Dec 28, 2021
    Posts:
    3
    I'm currently using the Rule Tiles from the 2D Tilemap Extras package, which automatically change to a specific sprite whenever they're next to other rule tiles. It's super helpful when designing play areas, as I don't have to pick each sprite individually to place, I can just draw and it looks good automatically.

    However, I can't figure out if I can have the rendering layer change as well as the sprite. I'm trying to get an effect where the player walks behind the wall and is hidden from the camera. For example, in Enter the Gungeon, the player can walk in front of the walls:

    upload_2022-12-2_16-19-30.png

    And behind the walls:

    upload_2022-12-2_16-19-44.png

    I can make my character walk in front of the wall like in the example, but I can't figure out how to get him behind it without him overlapping, like down below:

    upload_2022-12-2_16-20-24.png

    Any idea how i can make this work with the rule tiles? Much appreciated.
     
  2. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,513
    The thing to modify isn't the render layer but rather than Transparency Sort Axis.

    What you want is "objects with a larger y-position are rendered behind objects smaller in y." That's what the Transparency Sort Axis does.

    You need to

    1.
    Assign/verify (0, 1, 0) is your transparency sort axis. If you're using the 2D Renderer, this is on the 2D Renderer asset (see at top). If you're not, then it's within Edit > Project Settings > Graphics.

    2. Move the items that sort against the character to an Individual Mode tilemap (see the TilemapRenderer - you don't want Chunk mode), and set its Order/Layer to the SAME as the character. Now the character and items will sort against one another according to your sort axis.

    3. Give those item sprites a pivot point near the bottom. The pivot point describes the point that the sprite uses to sort against other objects. If the character is in front (lower y) of this point, it will render on top of the bookshelf.

    4. For your character, have its pivot point be near the feet. If your character is composed of multiple sprites, you may want a Sorting Group.

    Extra reading about 2D Sorting: https://docs.unity3d.com/Manual/2DSorting.html