Stunlock Studios' Technical Animator Albin Thunström showed the character animation workflow used in V Rising, discussed how the layers were made, and mentioned different approaches to animating.
Animation Layering is when you want your Call of Duty soldier running around and reloading at the same time without skipping a step. You play your running animation on the pelvis and down and your gun-related animations on the torso and up. Easy-peasy, right? Well, it’s not always that simple. What happens when you want to combine running with swinging a sword? And what if you want to be able to use the same animations for when your character is running and for when they’re standing still?
I’ll show you how we handled these problems in V Rising. While our game is made in Unity, our solution was actually inspired by an Unreal Engine live training video, which goes to show how sharing an idea or a concept can have an impact that you never anticipated and how beneficial doing so is for our industry. So this is me paying it forward. While Unreal solved this issue with special Unreal-specific animation nodes, we solved it in Unity through the clever use of character rigs, real-time IK, and nested blend trees.
Let’s get started!
To illustrate our problem, we start off by creating an Animator with two layers: one for the legs and one for the upper body animations. The leg layer usually has a blend tree that handles strafing in multiple directions, so we’ll add that. We add an Avatar Mask to the upper body layer that masks out the legs and then play a melee animation on it. You can find countless tutorials doing exactly this and leaving it there, but this is where we start to see the problem with doing so.
Just using Avatar Masks gives the chest the incorrect rotations.
Straightening out the spine
First off the torso animation will have incorrect rotations because the pelvis rotation, which by being higher up in the hierarchy influences the torso, doesn’t match the ability animation anymore since it’s masked out and only influenced by the running animations. We fix that by using a reference/proxy joint. This joint is parented directly underneath the character's root, but in Maya (or Blender, whatever you prefer) it’s constrained to the chest joint. That way, when we export our animations from Maya/Blender, this joint will receive the exact same position and rotation data as the chest without being influenced by the pelvis.
Now in our upper body Avatar Mask in Unity, we make sure to include this joint, which will leave us a perfect reference for exactly what the chest should look like. We then use IK to force the chest to match this reference joint. This can be used with a Chain IK Constraint from Unity's Animation Rigging package or with something like FinalIK’s CCD IK and Aim IK components. How you want to do it is up to you as long as you get the chest to match the rotation on every axis.
Correct chest rotation using IK.
Rotating the hips
The next problem is that when you play your melee attack, you might end up breaking your character’s back. A sword swing needs to convey power and force, but if you apply the necessary rotation to your torso while keeping your hips straight, you’ll get an unnatural (and for your character, probably painful) twist of the spine.
What we want to do is have the lower half of the body twist along with the torso without messing with the foot placements. How do we do that? Let’s try to visualize what that would look like. I would even encourage you to run around and try it for yourself! Imagine this: your character is running forward and their swing has twisted their chest so that it is facing to their right, along with their pelvis to support it, but the feet still need to run forward. Now, that would probably look like they are strafing to their left, but that left being forward (see GIF). Okay, cool, so how do we achieve this?
A pelvis twist results in strafing.
Imagine a normal two-dimensional blend tree for strafing (you can find it in any YouTube tutorial). In its simplest form, it contains 4 animations: run forward, run backward, strafe left, and strafe right. However, in all of these animations, the character is facing forward. Let’s instead replace all of these animations with blend trees of their own that support running in their designated direction, but that can also face every other direction. We’re pretty much reversing the setup, where a normal blend tree for strafing would run in all directions but only face one (being forward), these nested blend trees run in one direction but can face all directions. With this tree, we can now, without actually turning the character, run in all directions and face all directions.
All nested blend trees, running in their own direction but facing any direction.
We use four variables to control the Blend Trees: inputX, inputY, twistX, and twistY. The first two are the normal ones you need for a normal strafing blend tree – the dot products of the character's movement direction and the character’s right/forward direction. Here’s some pseudo-code for the sake of explanation:
inputX = Vector3.Dot(transform.right, velocity);
inputY = Vector3.Dot(transform.forward, velocity);
The other two variables control the nested blend trees and are the dot product of the character’s proxy chest joint’s forward direction (which we created earlier) and the character’s right/forward direction.
twistX = Vector3.Dot(transform.right, chestReference.forward);
twistY = Vector3.Dot(transform.forward, chestReference.forward);
In case you are wondering what a dot product is, it’s math magic. The simple explanation is: it takes two vectors and returns a float value. When the two vectors face the same direction, you get 1, when they face the exact opposite direction to one another, you get -1, and if they are perpendicular to one another, you get 0. This is exactly what we want for our blend tree! It might be a good idea however to remove the y-axis in these calculations since we’re only working in the two other axes anyway.
Basic Unity blend tree for strafing, but with nested blend trees.
And there we have our final result! Our chest is doing the exact same motion as the original animation intended. And even though the character could be running in any direction, the feet will always keep running in that direction while still allowing the pelvis to support the twist rotation in the chest. A nice bonus we got from this solution was that even in animations where the character is doing a spin, they could still do it while running since the feet and pelvis can support any direction.
Pelvis rotating along with upper body animation.
Twists are automatically supported. (Santa hats are not automatically included.)
Extra and alternative approaches
On V Rising, we actually didn’t use the chest direction when calculating the nested blend tree variables. Instead, we used another proxy joint, just like the one for the chest but for the pelvis. This way we didn’t overdo the twisting and also kept the rotation closer to the animator’s intentions. That is also what you’re seeing in these GIFs. Try it out for yourself to see whichever works best for you.
Another thing we did, which I also recommend, is switching out the melee animation when running to one that is keeping the spine much straighter. This way you can put the character in a position where they look less likely to fall over.
You could also do it the Unreal Training Video way, by not using nested blend trees (or blend spaces in “Unrealian”) but by actually rotating the character’s root instead. That way you don’t have to re-export rotated versions of the same animations in every direction – the normal strafe animations will do fine. However, you would also need to consider how you’d rotate your character’s root without altering the proxy joints.
Final result, running forward and to the left!
Thanks for reading! I hope this inspired you or gave you some new perspective on character movement animations. Now go make cool stuff!
Albin Thunström, Technical Animator at Stunlock Studios
You may find these articles interesting