Introducing the Animation Rigging preview package for Unity 2019.1
The Animation Rigging package for Unity 2019.1 enables users to set up procedural motion on animated skeletons at runtime. You can use a set of predefined animation constraints to manually build a control rig hierarchy for a character or develop your own custom constraints in C#. This makes it possible to do powerful things during gameplay such as world interactions, skeletal deformation rigging, and physics-based secondary motion.
We’re happy to introduce the new Animation Rigging as a preview package for Unity 2019.1. This blog post will provide an introduction and some examples of how you can use it. Please also check out the video of our Animation Rigging GDC 2019 presentation, it’s freely accessible on the GDC Vault.
You can now install the Animation Rigging package in your Unity projects from Package Manager. (Be sure to show Preview packages in the Advanced tab of Package Manager) The package page includes links to documentation along with some samples to help everyone get up to speed with using the package. This is our first release as a preview package for Unity 2019.1. You can also try out our next iteration for 2019.2 in the public beta. Using this upcoming version, you can use the Animation Window to author your own constraints animations with live feedback.
A brief note about what we mean by preview: please be aware that things in this package will change as we update to new versions. The exciting part is that you have the opportunity to influence our development and make sure it works for what you need. So please stay in touch with us and let us know how it goes. We are very eager to hear your input.
Animation Rigging overview
The Animation Rigging package provides a library of rig constraints that you can use to create procedural motion at runtime. This is commonly known as runtime rigging. The constraints are set up in groups called Rigs, which are assembled in the Rig Builder component that is assigned to the asset’s Animator Root.
This enables users to do powerful things with animated skeletons during gameplay, such as world interactions. For example, when a character’s hands interact with a prop, or to aim at a target in the world. It’s also possible to get higher quality rigging using procedurally controlled bones for skeletal deformation rigging, such as twist correction for shoulders and wrists on skinned mesh characters. We also have physics-based constraints that can be used for dynamic secondary motion on character rigs.
For working with rigs in the Unity Editor, it helps to see and interact with the skeleton in Scene view. We now have the Bone Renderer component, which allows you to add a list of transforms and display them in a variety of visual styles.
It often helps to organize parts of the skeleton using multiple Bone Renderer components. Here is an example where the same character has multiple Bone Renderer components so that the body, fingers and twist bones can each have their own display styles. This helps to facilitate different artist workflows such as rig setup, keyframing or gameplay debugging.
Rig Builder and Rigs
Here are instructions for setting up Rigs on a character:
- First, we need to add the Rig Builder component to the Animator root. This is the same GameObject where the Animator component is assigned. Typically, this is the topmost transform in the rig hierarchy.
- Next, we can create a new child GameObject and that is where we will add the Rig component.
- Finally, the Rig gets assigned to the Rig Layers list in Rig Builder.
This is the minimal valid rig setup. In the next steps, we add constraints.
The really great thing about Rig Builder is that the Rig Layers list allows for multiple rigs as seen in the image above. This is very useful for creating specialized behaviors that can be turned on and off during gameplay. And to make it even more useful, each Rig has its own weight value so it can be blended with the other Rigs.
Rig Constraints are the building blocks that are used to assemble rigs and produce procedural motion at runtime. They’re designed to be modular and general-purpose so that they can be combined in many different ways to solve the needs of your animation game designs in runtime.
Here is the list of Rig Constraints that are being released with the package.
Here are steps for how to set up a Rig Constraint. In this example, we’re using the TwoBoneIK Constraint.
- First, add a child GameObject below the Rig.
- Then we add a TwoBoneIK Constraint.
- Next, we assign the bones and effectors to the TwoBoneIK Constraint.
- Lastly, when Play is pressed we can see the Constraint evaluates at runtime.
Rig Constraints samples
The best way to get started and learn how the Rig Constraints work is by checking out the samples included with the package. Inside of Package Manager, there is a button to import the samples into your project. There is a scene for each constraint that demonstrates how it works.
Runtime rigging happens during gameplay. So in order to try out how this works, we made a quick gameplay prototype using some existing Unity sample content.
We implemented these basic player controls and used the Animation Rigging package to get some cool gameplay mechanics very easily. Here is a quick video of what it looks like:
Let’s take a look at each of these features so you can see how we made the runtime rigs.
Skeletal Deformation Rig
The ninja’s skeleton already had twist bones and skin weights set up to begin with. In Unity, we added TwistCorrection constraints to fix up the deformation on his arms and legs. The video shows what it looks like when these constraints are turned off. With the twist correction applied, the movement feels much more natural, like real anatomy and clothing:
Vertical Aim Rig: Shuriken
For the shuriken player ability, the ninja needs to be able to aim his throwing knives at any angle, 360 degrees.
- To set this up we first added some new virtual bones to his skeleton.
- Virtual bones in Unity are when you add new Transforms into the skeleton hierarchy and save them with the prefab. These can be animated like any other bone. They can be considered virtual because they may only have keyframes in the animation clips that need them, which saves memory elsewhere where they are not needed.
- Next, we added a TwoBoneIK Constraint to the left arm and set the virtual bones as the IK targets.
- The IK targets were then animated in a new animation clip where he throws the shuriken. This clip is set up in the ninja’s Animator State Machine as a replacement layer. Both this layer and the vertical aim rig are activated on button press.
- Finally, we made a 1D Blend Tree to drive the Aim Vertical virtual bone, which is the parent of the IK targets. This gets driven by player input, the vertical axis of the left analog thumbstick on a gamepad controller.
As a result, this animation layer overlays on top of any animation the ninja may be playing. This always works whether he is running, jumping, crouching or even attacking with his sword he can immediately throw a shuriken as a ninja should.
Vertical Aim Rig: Katana
The ninja’s katana also needs to be able to aim vertically in order to hit targets that might be on the ground or overhead. We made this building on top of the shuriken rig. It uses the same 1D Blend Tree to control aiming.
Sword animations bring a new factor: the horizontal rotation. It’s very important for this horizontal aim to be perfectly straight so that the sword trail effect looks smooth. It can be difficult to make this look straight using only skeletal animations because even if the poses are perfect, there are often imperfections in sub-frames. This is because of the way the interpolations solve on the arm’s FK bone chain. The best way to fix this is by using a Multi-Aim Constraint.
- We set up a new virtual bone and moved it out in front of the katana. Then we assigned this as the target of a Multi-Aim Constraint. The source object of this is the right-hand grip bone, which is the parent of the katana model.
- Next, we added another virtual bone as the parent of the aim target and used a Position Constraint to keep it centered on the ninja’s chest.
- Finally, we opened the sword swipe animation clip and added keyframes for rotating the parent of the aim target in sync with the motion of the arm.
The result is that the Multi-Aim Constraint corrects any imperfections in the horizontal rotation arc of the sword. Even when the animations are slowed down and have particle effects added as shown in the above video, the sword strike is always straight and true.
Butterfly Familiar Rig
Here is another example of how Rig Constraints helped us to make a follower character. We used the DampedTransform Constraint to make the butterfly follow a target Transform in the ninja’s prefab. It also uses a Multi-Aim Constraint to shine a spotlight that always aims at a target in front of the ninja wherever he goes.
You might recognize the butterfly model from our earlier blog post on the HD Lit Master Node for Shadergraph. What we didn’t know at the time is that this is the ninja’s messenger butterfly — he gives him power-ups and special attacks. Most importantly it keeps him company while he runs through the Megacity. Anyway, you can invent whatever cool gameplay mechanics you like and the Animation Rigging package makes it easy to implement.
Mechanical Crane example
The animation rigging constraints can not only be used for characters, but also for anything else. In this example, we used these constraints to build a futuristic mechanical crane rig. The goal was to create a rig that is entirely driven by inputs and constraints at runtime. There are no animation clips in this example, as all motion is derived from two gamepad joystick inputs and one button to trigger the clamp & release of the container.
Note: HDRP textures are not included in the sample project.
You can download mechanical crane sample project for Unity 2019.1 on GitHub.
The controls for the crane are:
In this example, we took the approach of creating two rigs. First, a ControlRig that basically mimics the model hierarchy in order to input and solve the desired result in an animation stream (aka the ControlRig)
The red part of the rig represents the inputs or desired targets, whereas the green represents the actual/current result.
Second, a DeformRig takes the final result of the ControlRig and applies it the model hierarchy + secondary piston movement:
The final result on the rig is then applied to the models or joints in the scene.
The inputs for the crane’s arm are driving rig effectors using a simple script and the Rig Transform component to obtain the proper scene/input evaluation. These inputs are then damped onto a second effector. The remaining effectors, including the container rotation and clamps, are children of this damped result. In this example, the ControlRig uses 15 constraints: Damp for the inputs, 2BoneIK for the arm, multiple constraints for the clamps and container release. The DeformRig uses a flat list of constraints: Aim & Multi-Position for the pistons & Multi-Parent Constraints for the rig-to-model remapping.
There are, of course, many ways that this example could have been rigged to obtain the same or similar result. Keep in mind that the rig hierarchy (order of GameObjects in the scene) controls the order in which the constraints are evaluated. This is extremely important in cases like this, where certain constraints need to be evaluated in a specific order.
Hope you’ve found this blog post useful in understanding how to manage inputs, Rig Transforms and different types of rigs & constraints. Have fun! We’re looking forward to hearing your feedback on the forums.
Want to continue learning about rigging? Check out our courses and tutorials on the Unity Learn Premium platform.
33 КомментарииПодписаться на комментарии