Randomize animation state in Mecanim, possible?

Hi
The client has thrown me a loop. What has happened is that the final animation assets do not match the proxy assets.
Instead of a single Idle state they now have given me three Idle states and I need to randomly choose the Idle animation state.
So I am wondering if the attached Mecanim state diagram is possible?
Is there some way thru code of deciding which particular animation state to branch to?

Hi, there are several ways. If you want to keep that look for your animator, you can add an int parameter for example, add a condition on each transition with a different value for that int, and set its value from a Random.Range each time you’re about to enter there (either in your character controller or in a StateMachineBehaviour added to walk_to_idle). You could also put the three animations in a blend tree with the same parameter (but as a float).

1 Like

Thanks. Guessing this is one area where Mecanim shines.
One area where it doesn’t is trying to achieve variable speed with baked transtion animations!
I was able to get it working by resetting the Animator default speed just BEFORE I triggered any transition.

Not sure how or where you’re varying your speed, but if its in the walk cycle to control character walk speed, there’s a better way to do it. Make a walk-in-place animation where the footsteps match the walk cycle as far as up-down goes, but not the movement forward-backward. Then blend between them to achieve smooth speed control without that slow-motion look.

1 Like