Faking depth in 2D

We now have a simple 2D scene that the Player can move around in, and appear in the correct order relative to other sprites in the scene.

However, the size of their sprite remains the same as the move around, making them appear as though they're shrinking as they move down ("closer" to the camera):

We can fix this with a Sorting Map, which can adjust the Player's size as they move vertically.

In the Scene settings section of the Scene Manager, click Create beside Default Sorting map to auto-create and assign a new Sorting map:

The new Default SortingMap object will have been created and placed in the middle of the scene. Looking at it from above, position it so that it appears just above the highest point that the Player can walk to, as seen in the Scene window.

We need to define areas that mark the region our Sorting Map controls. In the Sorting Map Inspector, click Add area to create one.

A new gizmo will appear in the Scene window, which can only be moved in the direction that the SortingMap's object faces. Move it downward so that it goes just below the bottom-most point of the ground sprite:

Notice the 1 in the middle of it. This represents the Order In Layer sprites that follow it will take. As we've already set up our sprite sorting in the previous tutorial (link), go to the Sorting Map's Inspector and uncheck Affect character sorting?. Instead, check Affect character size?:

We can now adjust the Start/end scale (%) values to control how small the character is at the top, and how large they are at the bottom. For the 2D Demo assets, try setting these to 80 and 120 respectively.

Re-running the scene should then see the Player resize as he moves along the Z-axis - making it appear like he is moving further from and closer to the camera.

Not seeing any change? Make sure the Player's sprite child object has a Follow Sorting Map component, and that Follow default Sorting Map? is checked in its Inspector.

Next, we'll improve the camera by making it follow the Player as they move.