Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

2D Isometric in unity 2D mode

Discussion in '2D' started by technos, Jan 6, 2014.

  1. technos


    Jan 6, 2014
    Hi Everybody,

    I'm learning Unity and to do so, I try to create the mechanisms of an "Age Of Empire" style game.

    I'm in the first steps, I have a A* pathfinding working approximately. My first tiles are ok, I have a human that can move around.

    My problem is the following ;

    I have created my project in the new 2D mode. (Good idea for 2D isometric game ? )
    I have set a Sprite which is a castle (lot of imagination...)
    I have set a Sprite which is a human.

    I try to make the layers working well, I mean when my human is behind the castle, we should not see it.
    When it is walking in front, we should see it.
    How can I achieve that ?

    Here is something similar to my problem.

    If it is not clear enough, it will be a pleasure to give more details or make a screenshot.

    Thank to anybody with tips !
  2. unitylover


    Jul 6, 2013
  3. technos


    Jan 6, 2014
    I would to give a little bit more details because I find no answer to my problem with Sorting Layers.

    When the little boy is in front of the caste, I would like to get this :
    When he is back, I would like to get this :

    Actually to only way is to change the sorting layers to get the different results... Imagine if I have 50 humans, this is not possible... I think...

    Do you have a different advice or a first direction to take with scripts ?

    Thank you for your help.
  4. gfoot


    Jan 5, 2011
    See also this thread:

    I've found that simply changing the Z value of transform.position works well for these dynamic situations. You must have all the sprites concerned on the same sorting layer with the same order-in-layer value; then the Z depth from the camera controls the overlap, just like normal.

    For non-dynamic situations you should still use sort order though.

    I would be concerned about the ground in your example, and I'd consider separating the sprite into two parts on different layers for that reason. It's pretty easy to author these things on separate layers in Gimp or Photoshop, and recombine them in Unity using two objects with their SpriteRenderers set to different sorting layers.
  5. TaewYn


    Jan 30, 2013
    Here is how I solved it for my game:
    -all foreground elements are on the same Sorting Layer
    -each element has a script attached, that changes the Order in Layer according to the Y position of it's feet/base
    -if I have a gameobject that consists of multiple sprite child objects (character limbs or so), I assign the same Order in Layer for all components and then adjust the sorting of the children via the z transform

    hope this helps :)
    RavenOfCode and Rutenis like this.
  6. fuedR


    Aug 30, 2013
    thats a pretty awesome method :)
  7. technos


    Jan 6, 2014
    Thank you for your help everybody,
    I had time to implement the idea from TaewYn and it works just great !

    My moving character has a script attached to it : In a lateUpdate() it is calculating the new z coordinate depending of his y position.
    My bulding have script attached that calculte their z coordinate on Awake() function.
    My ground is generated on Awake, in a different layer, using the Order in Layer to render it correctly.

    Thanks again TaewYn.
  8. BlackMat


    Jan 8, 2015
  9. akenaton


    Oct 11, 2013
    There is a free unity package X-UniTMX that can handles that with sorting order script and free Tiles Map editor:

    Look at the 2D iso example:

    For full information :

    I'm not a specialist of RPG development but I have an other question:
    What is the best for an Rpg quest game like Zelda: 2D or 3D?

    In 2D that needs a lot of pictures for player and ennemies animations:
    ie : Player moving in 8 directions (North South, Est, West, North-Est,South-Est...)
    if i want a player in different animation states(Idle,Walk,Run,Sprint,Attack, Defend,...)
    This player should also have all these animations with equipments( a small sword, powerfull sword, poor Armor,strong armor,shield,...) and in all directions.
    That means if we make 8 frames per animation, we have to make all this animations per state, per direction, per equipment.
    ie 8 direction times 8 frames =64 images x 8 states = 384 images x 8 equipment=3072 pictures in 512x512 to want a good quality for zooming.
    What about ennemies if we have ie 3 different type that means a lot of pictures nearly 10000!

    we can reach easily 2Go bytes or more.

    So if anyone has already made this type of game. Is 3D more efficient compare to 2D isometric?
    1) in terms of time development?
    2) In term of weight? definitively not for smartphones. only for PC or consoles.

    Sorry for my english. I'm french!
  10. TimK_personal


    Jul 30, 2014
    First of all, don't make 8 directions. Make 4, and then for the other 4 directions, mirror (scale = -1) across the appropriate axis.

    Second of all, don't animate your attachments as part of the core sprite. Look at something like Spine, which lets you do skeletal animation with sprites using 2D transforms.
    Ricna likes this.