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.
You want to read up on using sorting layers. Basically they allow you to setup different layers which specify a drawing order for each sprite on the layer. If you need something more advanced you’ll have to use code to change the display order.
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.
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
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.
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?
in terms of time development?
In term of weight? definitively not for smartphones. only for PC or consoles.
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.