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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Issues with multiple layers and collision in 2D tiled map

Discussion in '2D' started by mojohack, Nov 15, 2015.

  1. mojohack

    mojohack

    Joined:
    Mar 3, 2015
    Posts:
    6
    Hi guys,

    I'm currently working on a class project to create a 2d bomber-man-like game using Unity and I'm stuck at figuring out how to move my characters between layers while maintaining the integrity of the tiled map.

    Using Tiled Map Editor, this is the 15-by-11 map I created:



    And there are 14 layers in this map (11 layers for 11 rows and some others for miscs). So the order would be layer 1 is used to put on object on row 1 and so on for other layers/rows all the way down.

    The concern I have right now is I don't know which layer to use to put my character on (assuming I have a layer of collision objects and I will put my character in there).

    Say the character is at position (3,3) - row 3 - layer 3 (assuming origin is top-left), how is it possible for the character to [stay on top of/hide objects of] row 2, but is hidden by any object from row 4?
    --> If I station my character in one layer then this will not produce a desired result when my character moves from row to row.
    --> If I dynamically move my character between layers then the entire scenario will become quite complicated if I add move-able monsters onto the map and apply the same method?

    ---------------

    I'm using PopTag! as my reference right now btw.

    http://nxcache.nexon.net/poptag/game/1pdemo.html




    If this doesnt work out I might have to make the map completely 2D - 90 degree look down, or try with 3D and fix the camera angle to give the 2D feel.

    What other options do I have? Could someone help?
     
  2. sandboxed

    sandboxed

    Unity Technologies

    Joined:
    Apr 6, 2015
    Posts:
    95
    Disclaimer: Just skimmed through the question so this might not be the best answer.

    If you have each row on a different sorting layer, then use the SortingOrder to sort "within" each layer.
    This way your player, enemies, trees, boxes etc can all conform to the layering mechanics, and correctly occlude / be-occluded by the layers below and above.

    The player can take SortingOrder = 0, hence its always above anything else in the layer.
    Enemies can take 1 so that they appear above everything else, except for the player.
    Boxes/Trees can take SortingOrder = 2, so that they are behind anything in the given layer.
     
    theANMATOR2b likes this.