#Making Equipment sprites layer between parts of Player sprite

17 messages · Page 1 of 1 (latest)

lucid marsh
#

I have a player sprite that animates when it moves using a spritesheet. I want to add a system to equip tools/weapons or clothes. However, when adding the items as children of the player, the transforms update together as expected, but the tools look out of place, since they are simply on-top of the player, rather than being layered below the players hand, but still on top of the rest of the sprite.

I'm wondering how people go about layering equipment with the player, and other equipment?

Specifically, How do I achieve the look where a player is "holding" an item, in that, part of the item is behind the player sprite (behind the hand in this case), and the rest is in front.

Do I need to split up my player sprite into multiple parts to handle their z coordinate individually, or maybe i apply a rotation to the equipment so part of it cuts through the player hand and is "behind"? Or is the correct approach to "cut off" part of the sprite that should be hidden behind the player?

pseudo ingot
#

The Z component in Transform.translation is layering I think

edit: I am a fool

#

I think splitting it up is a good approach. Also makes it so you can have gloves 😉

lucid marsh
pseudo ingot
#

Yes. But you could create som wrapper struct that keeps tge limb Entitys of your player and loop through them to update the animation you want to play on a state change

#

Sorry kid woke up

lucid marsh
pseudo ingot
#
enum AnimationState {
    Running,
    Fighting,
    DoingTheJig,
}

/// put this on Player
#[derive(Component)]
struct MySplitSprite {
    limbs: Vec<Entity>,
    animation_state: AnimationState,
}

/// this would be your spritesheetbundles on each limb
#[derive(Component)]
struct SomeAnimationComponent {
    state: AnimationState,
}
impl SomeAnimationComponent {
    pub fn change_animation(&mut self,animation_state: AnimationState) {
        self.state = animation_state;
    }
}

fn my_split_animation_system(
    mut animation_query: Query<&mut SomeAnimationComponent>,
    mut player_query: Query<&mut MySplitSprite>,
) {
    for split_sprite in &mut player_query {
        for limb in split_sprite.limbs.iter() {
            animation_query
                .get_mut(*limb)
                .unwrap()
                .change_animation(split_sprite.animation_state);
        }
    }
}
#

Or something like that

#

Is how I would do it I THINK

#

But there are more smarterer people on here

#

I don't know if that compiles or not

lucid marsh
#

Thanks, that makes sense! Ill see if I can draw up a new player asset animation sheet with layers for limbs, and try this out 🙂

#

In theory, I was thinking, I only need the one hand to be separate from the rest of the body, I think

#

ahh, actually would run into a similar issue with legs/hands for clothing, nvm

pseudo ingot
#

I think I would do everything as a limb and keep the player entirely sprite less. I would create the sprites in asprite with each limb on a different layer

#

And then export them separately