0
\$\begingroup\$

My character has Idle-Walk-Jump-Attack state in animator. and it can change its appearance when it gets an item. for example, it can equip sword or armor. and i need to change whole sprite. the sword and armor are not separate with body.

which is best way to handle it?

before get item) Idle-Walk-Jump-Attack with sprite set 1.

after get item) Idle-Walk-Jump-Attack with sprite set 2.

how can i change animation state after get item? do i make every animation state in Base Layer?

\$\endgroup\$

2 Answers 2

1
\$\begingroup\$

When equipping items, it really is best to have them be separate from the rest of the sprite. Unless there are only a handful of items in the entire game that can appear to be equipped, it takes a lot of effort to remake every animation for every item. Additionally, if the player can have multiple items simultaneously, you will need to animate every combination of items too. And on top of that, all that work will have very little payoff unless each unique item needs to drastically change the animation of the character.

Equipping an item that is separate from the sprite isn't too difficult. If the item is static on the player, it can just be parented to the player's sprite and positioned fittingly. If it's animated, you can have a separate animator control the equipment's animations (or you can make the main animator do it which can get tedious).

If the item needs to move with the player's animations (IE a sword needs to swing with the hands of the player), you could either move the hands and sword in code, or you could make an empty game object that is animated to move with the hands in all the animations and then parent the weapon to that empty game object when it is equipped.

But if you really want to animate the player again for every single combination of items, and you don't have many items (or you have way too much spare time), then a similar approach to DMGregory's comment on Millard's answer may be appropriate. You would have a separate Boolean for each item (for a sword it would be "hasSword" and for armor it would be "has Armor") that is set to true when each item is equipped. Then, the animator would have transitions between each item's animation set (IdleDefault -> IdleSword, WalkingDefault -> WalkingSword, etc) based on those variables. And yes, every animation would be in the base layer.

\$\endgroup\$
0
\$\begingroup\$

What I would do is I would have a different animation for such states, like "walk" "walk_sword" etc. than, I would make different animation bools, like "isWalking" "isWalkingSword" etc. and then, I would have a boolean on the script that handles the animations, called hasSword, set to false. and then, at the point where you want to start the walk animation, you could type

if(hasSword)
{
   animator.SetBool("isWalkingSword", true);
}
else
{
   animator.SetBool("isWalking", true);
}

then, when you pick up the sword, you could set the boolean hasSword true.

This is tedious, but I can't think of another way of doing it.

I hope this is helpful.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ I think you can do this with just one extra boolean, "hasSword". You effectively duplicate your animation state machine with the two versions of each animation transitioning between one another using the same parameters. Then you add bridges between the two copies that transition based on the value of hasSword. The rest of your transitions, like from walk to jump & back, still use the same variables, just on a separate set of animation states. \$\endgroup\$
    – DMGregory
    Commented Sep 2, 2019 at 17:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .