Jamez0r

The perspective in my game is a sort of "overhead view" like the 2D Legend of Zelda games.

Sorting is done along the y-axis, where objects are drawn "top to bottom".



I'm trying to figure out how I could possibly set up some sort of configuration using Skeleton Render Separator / Skeleton Parts Renderer along with Sorting Groups to have parts of a single character be sorted into different y-values.

For example: Imagine there was an enemy character that was a huge spider with 8 legs, and the player character could run underneath it. The goal would be to sort each of the legs for the spider using the y-value where the individual legs touch the ground - that way the player could run in front of some of the legs or behind the others, etc. If I configure a Skeleton Parts Renderer for each of the legs, it would let me change the Layer or the Order-in-Layer for each of them but that would then prevent them from being y-axis sorted along with the Player and all of the other y-axis sorted objects. If I could instead somehow tell the Skeleton Parts Renderer to use a specific y-value (maybe using a Sorting Group?), I could have the pieces properly sort themselves along with all of the other y-axis sorted objects.

Any thoughts? :think:
User avatar
Jamez0r
  • Posts: 199

Harald

Interesting question!

The best solution that comes to my mind that still leaves sorting to Unity's camera sorting system is as follows:
  1. Create SkeletonPartsRenderers for each leg.
  2. Clear all SkeletonPartsRenderer OrderInLayer values to 0.
  3. Create a SortingFollowerLegN GameObject for each leg, add a BoneFollower component following <FootN> (bone location of the respective foot bone). Attach a SortingGroup component to it as well to set the sort point for all children to the transform position (which will be updated to the bone position).
  4. Re-parent each SkeletonPartsRenderer to the newly created SortingFollowerLegN object.

This setup sorts every limb according to it's transform position. The only problem is that it moves the Mesh around, so this needs to be compensated before drawing.

To fix this, you could create a script that updates the transform position of each SkeletonPartsRenderer back to the parent SkeletonAnimation position. Just be sure to call it in correct order, e.g. by using one of the SkeletonAnimation delegate callback methods so that it will not be called before the bone locations are updated.

Also be sure to attach a SortingGroup component to the characters that can walk between its legs to set the sorting point to their transform position as well, in case it uses the center of the character's mesh.
User avatar
Harald

Harri
  • Posts: 2091

Jamez0r

Harald wrote:Interesting question!

The best solution that comes to my mind that still leaves sorting to Unity's camera sorting system is as follows:
  1. Create SkeletonPartsRenderers for each leg.
  2. Clear all SkeletonPartsRenderer OrderInLayer values to 0.
  3. Create a SortingFollowerLegN GameObject for each leg, add a BoneFollower component following <FootN> (bone location of the respective foot bone). Attach a SortingGroup component to it as well to set the sort point for all children to the transform position (which will be updated to the bone position).
  4. Re-parent each SkeletonPartsRenderer to the newly created SortingFollowerLegN object.

This setup sorts every limb according to it's transform position. The only problem is that it moves the Mesh around, so this needs to be compensated before drawing.

To fix this, you could create a script that updates the transform position of each SkeletonPartsRenderer back to the parent SkeletonAnimation position. Just be sure to call it in correct order, e.g. by using one of the SkeletonAnimation delegate callback methods so that it will not be called before the bone locations are updated.

Also be sure to attach a SortingGroup component to the characters that can walk between its legs to set the sorting point to their transform position as well, in case it uses the center of the character's mesh.
Ahhh, very cool - I hadn't thought about re-parenting the SkeletonPartsRenderers. Awesome! Definitely will be giving that a try a bit down the road, thanks Harald! :bananatime:
User avatar
Jamez0r
  • Posts: 199

Harald

You're very welcome. :cooldoge:
User avatar
Harald

Harri
  • Posts: 2091


Return to Unity