Search Unity

Having troubles with layers and rule tiles

Discussion in '2D' started by JLT93, May 21, 2019.

  1. JLT93

    JLT93

    Joined:
    Jun 15, 2016
    Posts:
    4
    I'm terrible at explaining things but I'll give this my best shot. Note that collisions are turned off to test layers, and that the character moves on a tile by tile basis so collisions are typically bound to the grid square.

    A year ago when I first dabbled with Unity's Tilemap feature, I did things in a very redundant way. Trees were split into two layers (tree bottom, and tree top) and this is simply so that the character appears in front of the tree bottom and appears behind the tree top. I did the same thing for buildings (you were able to walk "behind" the very top of the roof).

    I lost all my progress due to a corrupted hard drive and some stuff were not recoverable. I decided to start over recently. I learned about the transparency sort axis (not too sure why it's a camera setting) and I was able to use a single tree sprite on one layer and be able to walk in front and behind in the fashion that I'd like.

    What I'm struggling with currently is buildings. The walls and roofs of the buildings are separate rule tiles and they occupy one square each. All buildings are on the same tilemap (named buildings, sorting layer is foreground, order is 0) but unfortunately I cannot get the same affect as I do the trees.

    On one of the lower buildings, my head appears correctly in front of the building. The windows (they're on a layer called Objects, also foreground, but layer order 1 as they disappear when in layer order 0) are in front of the character. That's not ideal, but I was unsure how to work around this. Any help with that would be appreciated. As for the building tiles themselves, I appear in front as expected:



    If I were to stand in the doorway however, things don't appear as I'd like. I'd like the players head to be behind the wall at this point because I'm effectively inside (there should be a warp and animated door sprite here but I haven't got that far)



    I must note that the buildings tilemap has a mode of chunk. I don't think sort order particularly matters for these as I'm not laying sprites on top of each other on the same tilemap (like the trees). The other buildings that are above this one, well, you basically walk behind all of it even when you're in front which is not ideal.

    If they're set to individual, we get a slightly different behavior. I'm able to be behind a wall (as shown in image) if I'm on the same tile as the wall but the door is still an issue where my head is in front of the wall. I've also been able to glitch it in some instances so that my character appears in front of the wall at all tiles.



    I must emphasize on the fact that the buildings are done using rule tiles so that I can have a variety of sizes and they also display different sprites depending on when there's a door. To do this, I have a rule tile that is hidden during play and it's on the same tilemap as the buildings. This is so I can have a custom rule for the buildings where if a door tile is the neighbor, I can display a specific sprite.



    What I'm trying to achieve:

    I'd like to be able to customize my buildings to my liking from size, to what's placed on them such as windows or signs.

    I'd like to be able to appear in front of the building + windows when I walk past them.

    I'd like to appear behind the building in any other situation (such as walking in a door way I'd like the building row above to cover my head).

    My question:

    How do I achieve what I'm wanting? I'm aware that it may not be possible to do all the things I'd like but I'm not sure what is the best method at the time of writing.

    Side question:

    I've noticed (especially in the preview 2D_IsoTilemaps_Project) that decorations such as trees, signs and other foreground things are not placed on the tilemap. Is that simply just to have more freedom to where to place objects?

    Mine are all on the tilemap because I want them to be bound to the tiles rather than placing them with freedom.

    Thank you in advance.
     
  2. SylvesterMolenaar

    SylvesterMolenaar

    Joined:
    Nov 6, 2018
    Posts:
    1
    I'm having the exact same problem, have you been able to fix it? I'm still looking for a solution
     
  3. raarc

    raarc

    Joined:
    Jun 15, 2020
    Posts:
    535
    the problem you have here is that you are trying to express height without defining it

    you are sorting the tiles by the y axis so as long as your character as a lower y than your tiles he will appear above them

    in reality, if you thought about it in 3d, the window tiles on the 1stfloor should have the same y value as the ground floor
    you need to find a way for the window tiles of the first floor to behave as if they had the same y value as the ground floor

    In my case i stopped using rule tiles and coded my own auto tiling and used the z axis for sorting, and all the tiles that are part of the same tall building are on the same z value.

    I have no idea how you can solve this without custom tools, as you said, foreground objects are usualy not placed on the tilemap because you can set the y value of the object base for them, no matter their height.

    If you made a big building sprite and set its anchor point on the base of the building you wouldnt have this problem.