Hello Forum,
last months I’ve broken my head on strategies how to handle my Animations for characters in Unity with the Unity-AnimatorController. For an overview I categorize this post text in three parts.
0. What I want to do
- What I know
- Problems and how I try to solve
My aim is not to get the one and only perfect solution, it’s more about the discussion about different ways and opinions to handle specific problems. Also about the way to get to different solutions and to talk about the advantages and disadvantages. I hope you’re all can be part of this discussion and feel free to solve this problems for further newcomers.
For the ones who did not know about some special topics. I’ve marked the technical terms with and at the End of this article you will find the links to specific descriptions.
0. What I want to do
I want to realize a relative complex AnimatorController [1] for an humanoid Character [2] with root motion [3].
For the first step I want to realize the mobility or. locomotion of this character. All the animations I want to use right now are already done and imported as FBX [4] to Unity, and prepared for my use case.
I try to categorize all my motions in a superficial level:
a) walk → forward, forward right, right, backward right, backward, backward left, left, forward left
same for → b) jog c) run and d) crouch
e) start → walk, jog, run, crouch forward
f) same for start from rest position to → 45°, 90°, 135°, 180°
g) stop → walk, jog, run, crouch
h) same for stop from rest position to → 45°, 90°, 135°, 180°
So in a nutshell the starts, does and stops of different kinds of motion in several directions.
There also planned several steps to equip my Charterer with standard animations.
Planned are i) Start Jumps, j) Landings and k) Dodges → in 8 directions of current look direction and
different kind of l) attacks.
So a really great part of the considerations is the extensibility of the system.
But first I want to came to a solution for a smooth and enjoyable movement for my character.
1. What I know
Basics about Animator Controller → States, Blend Trees, Sub State Machines, Transitions and Transitions Settings, Behaviors, parameters, layers [5]
Basics about state machines [6]
Basics about Unity-FBX-Settings-> Model, Rig, Animation, Materials [7]
Basic basics of design patterns. [8]
And also Basics about Scripting and the standard Unity features.
Basic organization of animations [9]
So my first tries had been the standard learn phase of a creating a simple state machine in the Unity-Animator by using normal states and transitions like to find in every standard tutorial on YouTube or other sources. Of course, this ended very soon in a confusing network of states, transitions and parameters.
Next I experimented with blend trees [10]. At first this concept determined a lot of my problems, but at the end some issues came with this solution. Blend trees are a great solution to capsule similar animations like walk, jog and run forward, but on the other hand a state in a blend tree is not defined as well, because it is a mixture of different states… in my opinion
2. Problems and how I try to solve
2.1 State definition of in between values:
Imagine I want to have a smooth transition from a locomotion animation (i.e. jog) to a stop animation (i.e. stop jog).
Lets say walk is from >0.2 m/s to <2 m/s → jog is from >2m/s to <5m/s and run from >5m/s. I can define this states by speed, okay… but for me it not seems a good way. Because this values are also are possible in start and stop animations.
So, how to define which states currently present without self query of the state in animator?
2.2 Blend trees with similar non similar states
So I came to the idea to handle all start and stop → walk, jog, run, crouch animations in a blend tree.
(Fig. 1)
Very soon I recognized that blend trees only works with floats in an “in between way”. This principal don’t work with non-similar animations. And believe or not: start → walk, jog, run and crouch motions are not-similar to each other. Same for stop animations.
(Fig. 2)
I had the idea to force set this animations in a blend tree by define natural numbers for the different animations (i.e. stop walk → 1; stop jog → 2; stop run → 3 (see Fig. 2 Threshold)), and force set them in script. This felt also like cheating, and of course this caused other issues. If in some case the stop state is not well defined and switches, weird (in between) animations are the consequence.
Is there a way to use blend trees on a safe and “non cheating” way to separate animations that have similar transition conditions, but different kind of motions?
2.3 Default of a Sub-state machine [11]
Meant are the Sub-states machines of the Unity-AnimatorController.
My next idea where to separate animations with similiar transitions, but different motions in a sub-state. Of course. This seems to be really a right way. But the great problem is the “default state” of the Unity-AnimationController, or rather the “default state” of the sub-state machine (see Fig. 3).
(Fig. 3)
Imagine currently the Character is something in between jog and running in this animation is well played in an blend tree… but now the character should stop. So if I make a transition from run/jog blend tree to stop-Sub-state machine, I’ve got a big problem. Unity demands a default state. But there is no default state. If the Character Runs before, the animation is “stop run”, if its jog, it’s “stop jog”, and so on (See Fig. 4 blue arrow).
(Fig. 4)
So I played with the thoughts to put a placeholder animation with little frames as default (See Fig. 4, Motion field), but I cannot define that placeholder as well. What it should be? jog, run, walk, stop walk, stop run…depends on the animation before and after.
Is there a good way to handle the default state of sub-state machines which are in close relationship to motion of the further and following steps?
I hope you all can understand my “problems”. How to handle complex multiple to multiple states conditions?!
I also like to discuss of different aspects and solutions and I am grateful and glad for every solution, contribution and thought process you you share with us.
Sources:
[1] Animator Controller (Unity - Manual: Animator Controller)
[2] humanoid Character (Unity - Manual: Using Humanoid Characters)
[3] root motion (Unity - Manual: Root Motion - how it works)
[4] FBX, filmbox format (FBX - Wikipedia & Unity - Manual: FBX export guide)
[5] Animation Controller, context (Controlling Animation - Unity Learn)
[6] Finite State Machine (Finite-state machine - Wikipedia)
[7] Humanoid animations (Unity - Manual: Importing a model with humanoid animations)
[8] Design Patterns (Software design pattern - Wikipedia)
[9] Animations Organization Concepts (Tipps für die Erstellung von Animator-Controllern in Unity)
[10] Blend Trees (Unity - Manual: Blend Trees)
[11] Sub-State machine (Unity - Manual: Sub-State Machines)