S&box Wiki

IKChains and Stride Retargeting

This guide is in need of a rework, as it does not explain how to use IKChains correctly, use at your own volition.

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.

Armature and Animation Changes in Blender

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:

  1. Select the model's armature and switch to Edit Mode with tab
  2. Create a new bone with alt+a, name accordingly in the Bone Properties panel (I'll use "root")
  3. Select the root bone and Extrude a new bone with e, press z and have the bones go upwards
  4. Name them in the Bone Properties panel, then Relations > uncheck the "Connected" box
  5. Repeat step 3 and step 4 for every foot needed
  6. Export your model
1.png

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.

2.png

Animations

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:

  1. Select the armature and switch to Pose Mode
  2. Select the target bones and go to the Bone Constraints panel
  3. Add a "Copy Location" constraint
  4. Select the armature as the "Target" > Select the respective foot bone as the "Bone"
  5. Repeat for all the bones, making sure the "Influence" slider stays at 1
3.png

This will result in the target bones following the foot bones throughout any movement.

  1. Still in Pose Mode, select all bones with a
  2. On the top-left of the viewport display, select Pose > Animation > Bake Action
  3. Check the "Visual Keying" box > Check the "Clear Constraints" box > Ok
  4. Export your animation
4.png

IKChains and Feet in ModelDoc

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.

  1. Add an "IKChain"
  2. Select the foot as the "End effector bone" > Ok
  3. Change "Target Bone" from the foot to the Target Bone
  4. Compile the model
9.png

Feet

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.

  1. Add a "Foot"
  2. Select the foot as the "Ankle Bone"
  3. If your model has a toe bone, select that as "Toe Bone" (optional)
  4. Place the "Ball Offset" where the ball would touch the ground
  5. Place the "Heel Offset" where the heel would touch the ground
  6. Repeat for all feet
  7. Compile the model
11.png

Trace Height and Trace Radius are mostly fine with the default values


Stride Retargeting node in the AnimGraph Editor

We advise against using this. It may be changed or removed in a future update. This feature relies heavily on paths and motors, which were prevalently used in Half-Life: Alyx, but have fallen out of use for various reasons in S&box, use at your own risk.

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:

  1. Add a "Stride Retargeting" node
  2. In "Feet": Add as many Feet as needed by pressing the + icon
  3. Use the dropdown lists to fill "Foot", "Target Bone" and "IK Chain" accordingly
  4. Repeat step 3 for all feet
  5. In "Ground IK": Check the "Enable Ground Tracing" box
14.png

Parking the Feet

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:

  1. Open the State Machine used for transitioning into your "idle" animation
  2. Select the transition arrow that points into your "idle"
  3. In the "Properties": check the "Park Feet" box
13.png

End Result

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.

striderr.png