Render Ordering - KSU-CS-Software-Engineering/VetMedSim GitHub Wiki
This page describes the functionality of script(s) responsible for changing the order of rendering of game objects. The reason for this feature to be added is because there are several game objects, which the player sprite can appear in front of or behind. If they remained in the same order, it would ruin the illusion of 3D space.
Usage
To use this script, you need to create a parent game object for any game object(s), which should position itself based on the relative position towards another game object. After all game objects, which should change their order, are located under this parent game object, attach Object/RenderOrderer.cs script as a component to the parent game object.
This action will also attach new Sorting Group to the parent group object (unless it already contains one). The script will change the values of this component. You can change the Order in group value if needed because it will not change.
Once you have done all of the previous steps, set the reference to the Orientation target in the script to the game object, to which all affected game objects will position themselves.
References scripts
- Object/RenderOrderer.cs
Functionality
The script will first look for Sprite Renderer components in all children of the parenting game object and compute the upper or lowermost point along the vertical axis.
Afterward, it will check the relative position of the Orientation Target on every Udpate call. If it moved below the lowest point and the sorting layer has a value of foreground, the whole group will advance to the background layer.
Similarly, if the Orientation Target moves beyond the highest point and group is in background it will move to foreground.
The group will remain its current sorting layer while the Orientation Target moves in between the lowest and the highest point.
Please note, that right now the values of foreground and background layer are set as constants. We decided to use this approach because currently, we use this script only for moving furniture based relatively to the player sprite. If a need arises for moving between different layers, please consider making foreground and background layer public properties.