I am making a top-down 2D RPG (Chrono Trigger, Final Fantasy, etc) and I am using the universal render pipeline with a custom transparency sort axis of (0, 1, 0). In my game, both characters and objects can be taller than 1 tile. I want characters to be able to walk in front of or behind tall objects depending on their y-position.
A player should be considered in front of an object if their pivot point y-position is less than the pivot point y-position of an object. For example, if the character pivot point is located at (0, 0) and an object pivot point is located at (0, 1), the character should appear in front of the object.
The above image shows the desired behavior and I have (mostly) achieved this result using the following:
- Sprites are on the same sorting layer
- Sprites have the same order in layer
- Sprites all have a
Sprite Sort Point
ofPivot
- I have set the pivots to match the example above
However, I run into a problem if I have two or more sprites at the same location. In my example above, I have two images—a wall and a window—and they both have identical dimensions and pivot points. I want to place one in front of the other.
If I change the order in layer of the window, it will appear on top of the wall but also the player—not desirable.
Or, if I leave them with the same order, the result is unpredictable—sometimes the window might be behind the wall, and other times it might look correct.
How should I approach solving this problem? Ideally I’d like to be able to have multiple images with the same layer, order in layer, and position, but control how conflicts are resolved (i.e., how the images with the same transform position should be ordered when rendered).
Any help is much appreciated!