How do I make a sprite made of multiple z order layers move in front of and behind objects smoothly

Okay, super new to GDevelop and have been trying to make an isometric pixel art life simulation game for ages in other programs but this is the first one that’s felt any bit intuitive to me.

But the roadblock has come with how to handle z order in my sprites for customization purposes.

I want to make a highly customizable character using premade sprite parts. Like different arms, different torsos, etc.
Ideally in the finished product the player can select different body shapes, hairstyles, set if they have prosthetic limbs, and wear a variety of clothes and accessories.

I know how to go about this. Every part is the same size as the player itself with their own animations. When layered it works fine. Figured that out on my own then went looking for solutions to the current problem and found someone suggesting that exact thing on the forum. Specifically this post.

I have a working player sprite that is just the body made from it’s collective parts.

My main concern is z order.

Right now Z order for the character is set by setting it to it’s z order to it’s Y(). This works in the sense that the z order is updating as it should be.

My first issue was that the layers were out of order when in motion. I fixed that by adding a number to the Y position of each. 1, 2, 3, 4 etc. to get the body parts layered in the correct way. This worked!

But…

I plan on having obstacles and creatures in the game that the character needs to pass in front of and behind. Right now, when the player passes a creature they pass through as each z layer part. Arm, then leg, then torso etc. Which makes the player look like they’re phasing through things. Diagonals also look wrong.

layeringdemonstration

But I’m concerned about how I’m going to set up my customization if I can’t fix this issue with the z layers of the sprite.

And for some reason Up and Up Right animations freeze and player invisibly moves until I hit a working direction. Still working on that but if anyone has suggestions there I will gladly take them. I’ve checked them over multiple times and the working events seem to be set up the same as the two that are glitchy.

Also, fair warning, I am sure my events are going to be a hot mess. I’m just getting started so I’m not familiar with the most efficient way of handling everything just yet.

Ideal End Result:

A player sprite made of multiple z order layered moving parts that can pass through entities or behind entities without the animation layers individually overlapping the entity one at a time.

Maybe the Y-Sort extension could help with this, this does seem like a relatively difficult feature to implement but its worth a try using YSort. You might have to mess around with the collision mask/bounding box of the sprites.

I could be wrong bc this is a new concept to me.

I would assign the scene objects a z order based on their y() but times 10 or 20. You need to guarantee enough space in the z order for all of the parts of your character. Let’s say times 10 for this example.

The character’s z order would be based on it’s Y() times 10 plus 1. The main part of the character or base would be at that value and then the others would be sequential. +1, +2 , +3

So, say there are 3 trees. Instead of 1,2,3 for the z order they might be 10, 20, 30. For the player instead of 1, 2, 3 it would be 11, 21, 31 … That would leave 9 z order slots for the other parts. You might need to use time 20 depending on how many layers the character has. The Y() would go unchanged only the z order is being spread out.

Does that make sense?

Hi CatkinTales

I’m doing the same thing as you but less detailed. My detailed bit is the hair as I have different hair styles and colors. I have a head, hair, and body as different sprites. Each time I create a person, a countperson variable goes up by one. Then each body part of that created person gets that variable number in an object variable. My people are draggable which is different to you but I also want them to go behind and in front of things.

My body is assigned a z order based on its y value and the other parts have their z order relative to the body. BUT, the Ysort extension didn’t work properly for me, it gave ‘separation’ between body parts so that people could go between a body and head etc of other people. Which is why I manually assign the z order to the y position. But I am using the y sort extension for the various non people objects.


Also, when I drag the people, the body object is draggable and the other parts are 'pinned' in place. To make sure that the correct body parts get dragged along with the body, I use those object variables mentioned earlier.

This shows the hair conditions. The other ones have other details related to other things.

Thank you guys! I did a sort of combination of your suggestions which involves referencing the nearest object (since there will be moving animals and npcs to take into consideration) It required a much higher additions and subtractions to the layers than I expected. So that is currently working! It’ll need refining in the future for sure but I’ve got a great jumping off point.

Now I just need to figure out this issue with the Up and Up Right directions not functioning right. I’ve remade the events multiple times. Everything is set up the same way between the events but for some reason if North or North East movements are enabled for any of the limbs the animation just freezes until the player moves to a different direction.

weirdteleportingdemonstration