- Home /
How to handle multiple animation variants
Hi,
I have a problem finding a good solution to animating characters when they have multiple variants of the same kind of animation. For example, let's say I have an NPC that can be in Idle, Move and Jump states, but I also want each of those states to have multiple animation variants (i.e. Idle01, Idle02, Idle03... Move01, Move02... etc.). I want to randomise which variant is played to make the NPCs less repetitive.
So far I tried a couple approaches but neither worked as well as I'd like. Best way I found so far was to implement the states (idle, move, jump...) as Blend Trees and then add the variants of each animation to those blend trees. Then just use bool parameters (isMoving, isJumping...) to switch between trees, and a float parameter to switch between different variants. But that means I'm sometimes blending between multiple variants (let's say I interpolate the value from 1 to 4, it will go through variants 01, 02, 03 and 04, instead just blending the 01 and 04 variants). And if I don't interpolate that value in any way, then it will just jump straight to a different variant with no blending.
Any ideas? It seems like something that shouldn't be that hard to implement, but I can't figure out a good way to do it.
Answer by Bip901 · Oct 05, 2019 at 12:37 PM
You could create a sub-state machine (e.g. "Idle"), which transitions to a variant (e.g. "Idle1, Idle 2, Idle3") based on an animator parameter. It could be an int that you set through script before starting the idle animation.
In the screenshot above you can see the controller of the player in my game. It can attack in multiple directions, so I created a sub-state called "Attack", which internally chooses an attack animation based on a parameter I set earlier, then goes back to the base layer.
Your answer
Follow this Question
Related Questions
Animator parameters 1 Answer
how to make multiple transition from one state? 1 Answer
Blending animations for a bow with differing charges 1 Answer
2DAnimator Freezes first time an animation is played 0 Answers
End of animation with animator. 0 Answers