In the previous chapter, we made a Control Rig for our Alien Plant. The Alien Plant Control Rig was a simple forward kinematics (FK) setup. Like we said in Chapter 14, Making a Custom Rig for Our Alien Plant with Control Rig, this is just like a basic parent/child hierarchy setup. In this chapter, we will set up the Control Rig for our Robot Drone. We will learn how to set up inverse kinematics (IK) for the arms of our Robot Drone as well as the rest of the Control Rig.
In this chapter, we will cover the following:
The following are the technical skills and software you need to complete this chapter:
The files related to this chapter are placed at https://github.com/PacktPublishing/Unreal-Engine-5-Character-Creation-Animation-and-Cinematics/tree/main/Chapter15
A character Animation Rig is normally a combination of FK and IK setups. The spine, neck, and head, plus things such as tails, are normally set up as an FK. However, things such as arms and legs are normally set up as an IK within an Animation Rig. On more advanced Animation Rigs, it is possible to set arms and legs up in such a way that they can switch between the IK and FK, but that is beyond the scope of this book. Most of the time, you want a good IK setup for your arms and legs.
Imagine we had an arm and a hand. We want to move the hand from A to B. With an FK setup, we will first need to rotate the upper arm joint and then the lower arm joint for the hand to reach B, as shown in Figure 15.1:
In reality, we'll have to keep switching between rotating the upper and lower arm joints until we reach B exactly. This is a very time-consuming process. Very early on in the history of computer animation, they invented a much more practical way to do this.
With an IK setup, we will simply have a controller (in IK setups, this is sometimes called an end effector) on the hand that we move from A to B. The 3D software will then automatically work out what the angles of the upper and lower arm joints should be, not only at the end keyframe of the animation but also on every frame in between, as shown in Figure 15.2:
Now, we just have one controller that needs to be animated for a hand to reach its destination. What is maybe even more useful is the fact that it also works in the inverse.
Imagine, for example, that we have a leg, and the foot of our character is planted on the ground while the body moves. We want our foot to stay in exactly the same spot on the ground while the body shifts weight. With an IK setup, the foot will stay with the IK controller (end effector) and lock it in place while the parent/body moves, as shown in Figure 15.3:
There's one more feature that can be added to most standard IK setups. We can add a controller that controls in what direction the knee or elbow should face when the limb is moving. It is commonly referred to as the pole vector. The knee or elbow will try to point in the direction of this controller. The pole vector controller is B in Figure 15.4:
The standard IK setup has three main elements, as shown in the preceding figure:
IK setup can be more than two joints, like in the case of the back leg of an animal like a horse, cat, or dog. These setups can be slightly more complex but in principle, they function in roughly the same way.
Now that we have learned what IK is, we can move on to learning how to set it up in a UE Control Rig.
Next, we will create the Control Rig controllers as we did for the Alien Plant in Chapter 14, Making a Custom Rig for Our Alien Plant with Control Rig.
Before we can start, we need to export the skinned robot and its skeleton from Blender. The Blender file can also be downloaded from https://github.com/PacktPublishing/Unreal-Engine-5-Character-Creation-Animation-and-Cinematics/blob/main/Chapter15/EndOffChapter13_Results_Drone_Skinned.blend. In Blender, we need to select all the parts of the robot as well as the armature and export it as an FBX file. The export settings are the same as what we used for the Alien Plant in the Exporting the Alien Plant from Blender section in Chapter 14, Making a Custom Rig for Our Alien Plant with Control Rig. Figure 15.5 provides an overview of the important robot export settings:
We have provided an already exported example of the Robot Drone if you want to use that instead. This exported FBX file can be downloaded here: https://github.com/PacktPublishing/Unreal-Engine-5-Character-Creation-Animation-and-Cinematics/blob/main/Chapter15/EndOffChapter13_Results_Drone_Skinned.fbx.
You can either import the robot into the existing UE project you created for the Alien Plant Control Rig setup covered in Chapter 14, Making a Custom Rig for Our Alien Plant with Control Rig, or you can create a new project. If you create a new project, remember to enable the Control Rig plugin. See Figure 14.2 and Figure 14.3 in Chapter 14, Making a Custom Rig for Our Alien Plant with Control Rig.
In the UE project in Content Drawer, import the exported robot FBX file with similar settings to what we used in Chapter 14, Making a Custom Rig for Our Alien Plant with Control Rig, for the Alien Plant, as shown in Figure 15.6:
To double-check whether everything has been imported correctly, double-click the Robot Drone SKELETON file to open it, as shown in Figure 15.7:
If everything is correct, when you select the root bone, in my case, Root_Robot, the position and scale transforms should be 0.0, 0.0, 0.0 and 1.0, 1.0, 1.0, respectively.
Our Robot Drone is now imported. Next, let's create the Control Rig.
Just like we covered in Creating the Control Rig node on the Alien Plant in Chapter 14, Making a Custom Rig for Our Alien Plant with Control Rig, as shown in Figure 14.9, in Content Drawer, right-click on the Skeletal Mesh object and select Create Control Rig, as shown in Figure 15.9:
Double-click the Control Rig object to open up the Control Rig interface.
Let's think about what controllers we need for our Robot Drone. Our Robot Drone needs the following:
Now, let's create the controllers we need to drive our Robot Drone. This is done in the same way we covered in the Creating basic Control Rig controllers section in Chapter 14, Making a Custom Rig for Our Alien Plant with Control Rig, so I'll be going through these steps in less detail here:
Next, we'll create the controllers for the claws on the hands in a slightly different way so we can see what they will look like in the final position.
The claw controllers will be unparented from the bones and move to the bottom of the Rig Hierarchy window with the other controllers.
We should now have something as in Figure 15.18:
We have now created all the controllers we need for our Animation Rig. Next, we'll organize them in the correct hierarchy.
In this section, we need to organize our rig controllers in the correct hierarchy. Just like with all our parent/child hierarchies in our Animation Rigs, the hierarchy needs to be parented in the right order, so our rig works correctly.
Like with our Alien Plant Control Rig, we need to figure out how we want our hierarchy to work.
Firstly, we want an overall root controller (RobotRoot) that can move our entire Animation Rig if we need to. That needs to be at the top of the hierarchy and the parent of everything in the Animation Rig.
Secondly, we want the body controller (RobotBody) as the child of the root controller. We just need to left-click to select and hold the mouse button to drag the RobotBody controller on top of the RobotRoot controller, as shown in Figure 15.19:
Following that, RobotLeftHand, RobotLeftElbow, RobotRightHand, and RobotRightElbow should be the children of the RobotBody controller, as shown in Figure 15.20:
Finally, the claw controllers should be the children of their respective hands, as shown in Figure 15.21:
Our controllers are now in the right hierarchy, but they do not line up with our bones yet. Next, we'll do that like we did in the Positioning the controllers on the joints section in Chapter 14, Making a Custom Rig for Our Alien Plant with Control Rig.
To line up the controllers to the bones, we need to copy the bone transforms and paste them onto the controllers. Like with the Alien Plant, we need to start at the top of the hierarchy with the parents and work our way down. We'll leave the RobotRoot controller at the origin of the scene.
Let's line up the RobotBody controller first since it's next in the hierarchy:
We do this since we want the elbows to point toward them, so they need to be a bit offset. This is how IK pole vector controllers work. Later in this chapter, you will see this in action.
We have now created and positioned all the controllers we'll need for our Robot Drone Animation Rig. Next, we need to link the bones to the controllers in Rig Graph.
This first part of the process is the same as what we did for the FK setup in the Controlling the Alien Plant skeleton with the controllers section in Chapter 14, Making a Custom Rig for Our Alien Plant with Control Rig:
Now, we will do something a bit different from the Alien Plant rig. This is purely to help us organize more complex rigs visually more easily in Rig Graph.
We now know at a glance that these nodes in the rig control the main body of our Robot Drone.
Next, we'll create the setup for the left hand and the two claws.
Now, all the controls for the left hand of the Robot Drone are grouped together. Adding these comments does not change the functioning of the Animation Rig. It is just a visual tool to quickly make sense of a more complex rig. This rig is not complicated, but in the future, you might do much more complex setups than this.
We have now set up the standard FK parts of our Animation Rig, the body and both hands with claws. Now we can set up the arms with IK.
Before we set up the IK controls, we need to get a few bits of information from our arm skeleton. This is going to be used later to set up the orientation of our IK control.
In the Rig Hierarchy window, right-click on the L_Arm_Lower bone and select Control Bone Transform, as shown in Figure 15.31:
This will display the local transform of the bone. Make sure it's set to Local Space and select Move, as shown in Figure 15.32:
Notice that the Z axis (blue Z arrow) is pointing directly down the arm toward the hand. Note this direction down as +Z (if the blue Z-axis arrow were pointing in the opposite direction but along the same axis to the hand, it would have been -Z).
This +Z value is what we will use later as the primary IK axis. Now note in what direction axes the elbow is mainly pointing (in this case, toward the ground). This would be the +X axis along the red X arrow. This +X value is what we will use later as the secondary IK axis. Note this down too.
These primary and secondary values we note down now will simply tell the IK controller in what direction our elbow bends when we input them later in this chapter. Now that we have these values, we can build our IK setup.
To set up the IK controller, there's a Basic IK node in Control Rig that takes care of everything. Let's create it:
This creates the Basic IK node shown in Figure 15.34:
In the Basic IK settings, there are Item A, Item B, and Effector Item. These are the three bones that will be in our IK setup:
Remember to connect the Execute socket from the last Set Transform - Bone to the Basic IK Execute socket. Otherwise, Basic IK won't be activated. The robot's left arm will look broken at this point. No need to worry about that since we need to set up the rest of the settings before it will function correctly.
Next, we want our RobotLeftHand controller to be the thing that the IK aims for. Just like it controls the L_Hand bone position, it can also control the Effector position.
Now we'll use the values we got from the Getting bone orientations of our arm bones section of this chapter to input the correct values under the primary and secondary axes.
Expand the Primary Axis and Secondary Axis settings by left-clicking on the small arrow in front of their names. The value we noted down for Primary Axis was +Z, so set Z to 1.0 (1.0 = plus and -1.0 = minus). Make the rest 0.0.
The value we noted down for Secondary Axis was +X, so set X to 1.0. Make the rest 0.0, as shown in Figure 15.37:
The arm will still look broken, but less so. This is because the pole vector controller (the direction that the elbow points) is set to be at the origin of the scene by default. We created the RobotLeftElbow and RobotRightElbow controllers for this reason, so now, let's hook up the RobotLeftElbow controller to our Basic IK settings.
This is because pole vectors are not influenced by rotation or scale. They are merely points in space that the elbow or knee can point to.
The arm should not look broken anymore. The IK setup for the left arm should now be complete. Next, let's test the IK setup.
You can now test the left arm IK by moving the RobotLeftHand and RobotLeftElbow controllers. Remember not to undo after moving the controllers in the Viewport; when wanting to return them to the original positions, press Compile instead. If you undo, it will undo the work you just did on your rig setup.
Particularly look how the elbow points to the RobotLeftElbow controller when you move it, as shown in Figure 15.39:
Hopefully, this will help you to understand what a pole vector is when you see it in action. Move and rotate RobotLeftHand and see that the arm bones automatically bend to always reach the hand. This is IK in action. You can also select the claw controllers and rotate them as a test.
If you're happy with how everything works, repeat this process to create IK controls on the right arm. Test it all, as shown in Figure 15.40, and save your UE project once you're done:
We have provided the completed Control Rig for the Robot Drone in the final project file, which can be downloaded from here with installation instructions: https://github.com/PacktPublishing/Unreal-Engine-5-Character-Creation-Animation-and-Cinematics/tree/main/FullFinalUE5Project
The example Control Rig is under Content/RobotDroneControlRig.
Your Robot Drone Animation Rig is now complete.
In this chapter, we learned how to correctly export our Robot Drone from Blender and import it into UE. We learned what IK is. We also built a basic FK rig for the body controls and then set up IK controls for our Robot Drone arms on the same Animation Rig.
If you can set up basic FK and IK on an Animation Rig, you're well equipped to set up almost any basic character rig and can achieve a lot. Rigging can be very complicated on complex rigs, but these two basic building blocks of basic FK and IK setups are at the core of it all.
In the next chapter, we will do some animation on these Animation Rigs we created.