Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Feature Request Proposal: Different Tile Map layer modes

Discussion in '2D Experimental Preview' started by DevAndArtist, Jul 1, 2016.

  1. DevAndArtist

    DevAndArtist

    Joined:
    Jun 28, 2016
    Posts:
    7
    Different Tile Map layer modes

    Introduction
    This is a follow up proposal to the tile offset ability which aims to create an additional workflow by reducing the need of different tile map layers to solve a specific design problem.

    Motivation
    Let's pretend Unity will gain the ability to offset individual tiles inside of each tile map layer.


    This will allow us to reduce the amount of layers to create visually maps like this (source):


    The amount of layers *could* be reduced to three:
    • Ground
    • Buildings
    • Objects
    The problem that raises with this approach will show itself when we'll try to add characters into the game. As you might now the current tile maps and their layers are flattened together and there is no way to move a character behind a certain tile of a specific layer (not behind a specific layer)!!

    Lets just think only about the ground layer which might have offsetted tiles. This might look like this (source):


    It is clear that some tiles appear behind others, because some tiles underneath are raised (offsetted on the y-axis).

    Now we want to add another layer in-front of the ground layer with some objects for the exact same ground structure. Lets say we place one object on top of one ground tile, but there is another ground tile underneath which is offsetted to appear at the same position as our current ground tile. The problem here is clear, because our object tile does not appear behind the offsetted ground tile, where it visually should.

    Here is a simple example. Lets pretend we have this tile structure for our ground and object layers:

    A1 | A2
    B1 | B2​
    1. Lets say we offset B2 of the ground layer to appear at A2's position (we simply raise the ground tile).
    2. Now we put an object on the object layer at A2.
    3. The Problem is that the object at A2 appears in front of the ground layer tile from B2, which visually it shouldn't.
    Proposed solution
    Add a new layer mode to the whole the Tile Map object. The new layer mode could be called `Intersecting` where the current mode will be called `Overlaying`.

    With the intersecting mode the tiles are sorted and rendered based of the tile grid coordinates of the layer (not the real coordinates). I believe there must be a way (or by default) to set the origin tile on each layer for this. All other tiles will then take this into account. Only one single tile per layer can be marked as origin, where the other tiles will have its computed grid coordinates.

    You can think of it as an array of array with tiles from different layers:

    [[A1_g, A1_o], [A2_g, A2_o],
    [B1_g, B1_o], [B2_g, B2_o]]
    Where the current overlaying mode is more like this:

    [[A1_g, A2_g, B1_g, B2_g],
    [A1_o, A2_o, B1_o, B2_o]]
    With the intersecting mode the object from the above example will now appear correctly behind the offsetted B2_g tile. Visually it from the side it will look like this:

    <A2_g, A2_o, B2_g>​
    <B2_o>​

    Sorting layer and order in layer will still be taken into account for this calculation. However, I believe the sort order must retain the same on all layers while using the intersecting mode.

    Check this short video of an isometric game called Wakfu for a visually better expressed example at 0:24 where a character appears behind and then in front of the building tiles based on his y-position (or y-tile-coordinate).


    By now we only solved the problem with the layers but not the problems with player characters.

    To solve the mentioned issue we need to decouple all tiles from all layers from the flattened version, this would also provide good visual debugging.

    When using the intersecting mode you should get a few new priorities on the tile map object to set and one new computed property.
    • Tile range (settable property with two values which are never equal - min and max) - defines a range in which all tiles are equally offsetted on the z-axis based on the sort order property. (Tiles from different layers for a specific tile position like <A2_g, A2_o> can remain flattened.)
    • Tile distance (computed property - read only) - defines the distance on the z-axis between each tile (remember tiles with the same grid coordinates from different layers can retain flattened).

    The tile distance is recalculated whenever a new tile added or removed which extends or shrinks the the current map boundary. The map boundary is calculated from all tiles from all layers of an Tile Map object.

    Here is a visual example where g means its a tile from the ground layer and o a tile from the object layer. e means its an empty tile. The ground layer is behind the object layer:

    go | go | ee | ge
    ee | ee | go | ee

    ee | go | go | ee​

    Lets say the (red) go tile is the origin tile with the coordinates (x: 0, y: 0). The go tile at the top left corner has the coordinates (x: -1, y: 0) and defines the minimum of the width boundary. The ge tile at the top right corner defines the max boundary for the tile map and it has the coordinates (x: 2, y: 0) - even if there is no tile present on the object layer! The boundary width is for this example is equal 4. The hight of the boundary is equal 3.

    If we would remove the texture from the origin go tile (the tile is still the origin even with no texture) the boundary will remain the same and tile distance won't be recalculated. However when we remove the texture from the top right ge tile, the boundary width will shrink to 3 and we must recalculate the tile distance and reposition all tiles based on the tile range we specified.

    Because now we have a computed propoerty of the tile distances (equal between neighbor grid tiles) and for instance for the sort order `Top Right` the bottom left tile is guaranteed to sit at the minimum range and the top right tile is guaranteed to sit at the maximum range on the z-axis, we can calculate the z-position for our character based on his y-position so in our game the character will appear behind and in front of specific tiles.

    PS: I hope this proposal is understandable to the reader. If you have any specific questions please let me know, I'll try to answer them as easy as possible. I also could provide some hand drawings to visualize my ideas.

    PPS: Long story, short meaning.
     
    zyzyx likes this.
  2. DevAndArtist

    DevAndArtist

    Joined:
    Jun 28, 2016
    Posts:
    7
    Here is a quick drawing for the new intersecting mode.


    The bottom left tile is in front of all other tiles, where the top right tile is behind all tiles. At the right is the tile map object with flattened layers, where on the left is the way we keep thinking of these layers.

    The intersecting mode has also a constant computed tile distance between each tile (based on the current tile map boundary size and the tile range). As for this example I used the sort order: top right.
     
    zyzyx likes this.
  3. Johaness_Reuben

    Johaness_Reuben

    Joined:
    Jan 27, 2016
    Posts:
    253
    Hi,
    Thanks for posting all the info. I've been looking into this and it is an issue while working with isometric games. Generally, when only there's only a single level involved it's not a problem. Multiple levels though like Wakfu can be tricky and difficult.
    Currently looking into different solutions and will consider your suggestion.
     
    DevAndArtist likes this.
  4. DevAndArtist

    DevAndArtist

    Joined:
    Jun 28, 2016
    Posts:
    7
    Thanks, I really hope something like this will see its day light in Unity. :)