IKChains and Stride Retargeting
This guide will serve as an entry-level tutorial for adding all the required modifications to a model, its armature, and its animations before being able to use Source 2's IKChain and Stride Retargeting systems.
IKChains in Source 2 work as they do in many animation programs, they require "target" bones outside of the feet's hierarchy, sharing no parents, these targets are superimposed onto the feet at all times, so the animations will need to be modified to reflect that.
To create the target bones the process in "Blender" is as follows:
- Select the model's armature and switch to Edit Mode with tab
- Create a new bone with alt+a, name accordingly in the Bone Properties panel (I'll use "root")
- Select the root bone and Extrude a new bone with e, press z and have the bones go upwards
- Name them in the Bone Properties panel, then Relations > uncheck the "Connected" box
- Repeat step 3 and step 4 for every foot needed
- Export your model
shown are the root bone and 2 target bones (selected in pose mode), the position in edit mode is arbitrary.
In step 3, the size of the bones is irrelevant as the engine doesn't support bone size, the direction of the bone, however, is important, not particularly in this process but it's good to keep the bones axis aligned, additionally, in Blender, you can press shift + n to align the roll too.
In Source 2, only the base of the bone is used, but Blender also gives the bone a head, that is why the size doesn't change when moving the head but the direction does; Shown below are the 2 separate hierarchies.
Now the targets will need to follow the feet in the animations, do this for each non-additive animation that contains any foot movement, including idle:
- Select the armature and switch to Pose Mode
- Select the target bones and go to the Bone Constraints panel
- Add a "Copy Location" constraint
- Select the armature as the "Target" > Select the respective foot bone as the "Bone"
- Repeat for all the bones, making sure the "Influence" slider stays at 1
This will result in the target bones following the foot bones throughout any movement.
- Still in Pose Mode, select all bones with a
- On the top-left of the viewport display, select Pose > Animation > Bake Action
- Check the "Visual Keying" box > Check the "Clear Constraints" box > Ok
- Export your animation
For IKChains to work in the AnimGraph editor, a model just needs IKChains added in the ModelDoc, however, to use Stride Retargeting you also need to specify a "Foot", Stride Retargeting incorporates the foot locking function of regular IKChains while also calculating how to move the foot accordingly during the animation.
- Add an "IKChain"
- Select the foot as the "End effector bone" > Ok
- Change "Target Bone" from the foot to the Target Bone
- Compile the model
Valve has very specific nomenclature, for example, what would commonly be called the foot bone is called ankle, the "Foot" parameter also contains a "Heel Offset" value and a *"Ball Offset" value, the ball being the name for the padded part of the foot that touches the ground that's not the heel, under the toe joints.
- Add a "Foot"
- Select the foot as the "Ankle Bone"
- If your model has a toe bone, select that as "Toe Bone" (optional)
- Place the "Ball Offset" where the ball would touch the ground
- Place the "Heel Offset" where the heel would touch the ground
- Repeat for all feet
- Compile the model
Trace Height and Trace Radius are mostly fine with the default values
Stride Retargeting is best used for applying small corrections, so use it in conjunction with either strafing or standing turns, the biped example animgraph in the intro contains both, useful for NPCs or Players; Set up a basic AnimGraph:
- Add a "Stride Retargeting" node
- In "Feet": Add as many Feet as needed by pressing the + icon
- Use the dropdown lists to fill "Foot", "Target Bone" and "IK Chain" accordingly
- Repeat step 3 for all feet
- In "Ground IK": Check the "Enable Ground Tracing" box
When transitioning into idle the IKChain may leave the model in an awkward pose, to make sure feet are reset correctly you'll need to enable it in the state machine:
- Open the State Machine used for transitioning into your "idle" animation
- Select the transition arrow that points into your "idle"
- In the "Properties": check the "Park Feet" box
Since all parameters have detailed descriptions, the remaining steps are to work around which work best for your model and are subjective. The final result will see the feet move accordingly:
These example legs are only using a "walk forward" animation, and a path motor to drive it towards the set path, it is recommended to have multiple directional movements for strafing.