V Rising's Animation Layering in Unity

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.

Final Result

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

Join discussion

Comments 5

  • C C

    Really love the article and the style in V Rising, and I've been trying to follow it because I'm creating a similar locomotion system.

    However I feel there's a gap in my knowledge and would love some further details in your article around:

    "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."

    Could you give an example screenshot of how that looks in maya (or blender) and what the hierarchy looks like in Unity once it's imported?

    Could you also show a screenshot of what it looks like in the Avatar Mask file?

    I'm trying to modify existing animations to add this proxy joint (I'm assuming it's a new bone?)

    Would it also be possible to give an example of how we'd use IK to force the chest to match this reference joint? (Could be in Chain IK or FinalIK, doesn't matter)


    C C

    ·8 months ago·
  • Thunström Albin

    I can't post any pictures here, but I'll try to make myself clearer.
    In the article I make an assumption that your character rig has a "root joint" that is NOT the pelvis joint. Many rigs start the rig hierarchy with the pelvis (which makes it the root), but we can't do that in this example since we are animating the pelvis, which means everything underneath it will also get manipulated (and that is actually the initial problem and why the chest is moving strangely). Therefore we make our root joint (the joint highest up in the hierarchy) just a joint that we place on the ground underneath the character. This joint we DO NOT ANIMATE. Under this root joint we have e.g. our pelvis (which among its children of course contains the rest of the body), as well as our "proxy joint" which is just a sibling to the pelvis. Our "proxy joint" exists here because it needs to be a part of the rig (aka under the root) but it can't be in the pelvis' hierarchy.

    Now, I'm assuming you already have some animations, probably from Mixamo, right? We might be able to fix it like this: We open our animation in Maya (Blender is fine but I don't know it as well). We create a new root (placed on the ground), we place the old joint hierarchy under it, and we add a new joint (the "proxy joint") under the root as well. We position the proxy joint so that it has the exact same position and rotation as our chest joint. We parent constrain our proxy joint to our chest joint, so our proxy always follows the chest. Then we bake our animation (Edit > Keys > Bake Simulation) so that our proxy joint gets keyframes based on the chest (because we can't bring the parent constrain into Unity), and BOOM! We just baked down all the chest information onto our proxy joint.

    Now in Unity you just have to make sure that when you create an Avatar mask that does not contain your legs, you still keep this proxy joint in the mask. That way this proxy joint is showing you the chest values based on the animation you are tyring to show on that layer, and not what the layer underneath is doing.

    Also use Generic Rig in Unity since Humanoid masks out joints it deems unnecessary. And make sure all your animations AND your character rig has the same joint hierarchy (now that you've manipulated one animation you have to do it to all the others, and make sure they match the skinned rig. They need to look the same!).

    With whatever IK solution you try, it's not a lot more that just writing "I want the IK target to be in the exact position as the proxy joint". If this IK rig doesn't provide rotation manipulation (e.g. I'm not sure the Chain IK Constraint do) just use something like the Multi-Aim Constraint on the chest and write "I want the aim target to be in the direction of the proxy joints forward direction". This is how you "force the chest to match this reference joint".

    Hope any of this helped.


    Thunström Albin

    ·3 months ago·
  • Anonymous user

    Thanks for the article. This is a seemingly common issue that doesn't appear to have a well documented solution in Unity (that I've been able to find), which is quite puzzling as a newcomer to the engine.

    As per CC's previous comment, it would be immensely helpful if you could elaborate on the section "Straightening out the spine" to point people down the right path.


    Anonymous user

    ·4 months ago·
  • Anonymous user

    Great article! Thank you for sharing this. This is what really stump me with the layering system in Unity. My character always a jittery mess with the upper body override 😂. I'll try this approach this weekend.😍


    Anonymous user

    ·6 months ago·
  • Anonymous user

    Thanks that’s really helpful!


    Anonymous user

    ·9 months ago·

You might also like

We need your consent

We use cookies on this website to make your browsing experience better. By using the site you agree to our use of cookies.Learn more