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.

2D Isometric in unity 2D mode

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

  1. technos

    technos

    Joined:
    Jan 6, 2014
    Posts:
    5
    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.
    $tile-diamond-bad-order.png

    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

    unitylover

    Joined:
    Jul 6, 2013
    Posts:
    346
  3. technos

    technos

    Joined:
    Jan 6, 2014
    Posts:
    5
    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 :
    $Unity_human_In_Front.jpg
    When he is back, I would like to get this :
    $Unity_human_Back.jpg

    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

    gfoot

    Joined:
    Jan 5, 2011
    Posts:
    550
    See also this thread: http://forum.unity3d.com/threads/220231-Dynamic-draw-order-or-2D-Z-buffer

    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

    TaewYn

    Joined:
    Jan 30, 2013
    Posts:
    19
    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

    fuedR

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

    technos

    Joined:
    Jan 6, 2014
    Posts:
    5
    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

    BlackMat

    Joined:
    Jan 8, 2015
    Posts:
    250
  9. akenaton

    akenaton

    Joined:
    Oct 11, 2013
    Posts:
    9
    Hi
    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

    TimK_personal

    Joined:
    Jul 30, 2014
    Posts:
    18
    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.
     
    hickna likes this.
unityunity