S&box Wiki

Revision Difference

IKChains_and_Stride_Retargeting#529729

<cat>Dev.Model</cat>⤶ <title>IKChains and Stride Retargeting</title>⤶ ⤶ 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.⤶ ⤶ All parameters are already documented, detailed descriptions and comments are available inside ```biped_standard.vanmgrph``` that comes with Half-Life: Alyx in the *"custom_character"* preview addon.⤶ ⤶ *(Half-Life Alyx\content\hlvr_addons\custom_character)*⤶ ⤶ # 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 <key>Tab</key>⤶ 2. Create a new bone with <key>Alt</key>+<key>A</key>, name accordingly in the **Bone Properties** panel *(I'll use "root")*⤶ 3. Select the *root* bone and **Extrude** a new bone with <key>E</key>, press <key>Z</key> 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⤶ ⤶ <upload src="a4aaf/8d9073253bb4b50.png" size="114480" name="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, once exported in either SMD or DMX format, they will be resized automatically to 2.605mm, the direction of the bone, however, is important, not particularly in this process but it's good to keep the bones aligned.⤶ ⤶ 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.⤶ <upload src="a4aaf/8d90733ec8320e4.png" size="5825" name="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⤶ ⤶ <upload src="a4aaf/8d90735ea2c36da.png" size="95813" name="3.png" />⤶ *`This will result in the target bones following the foot bones throughout any movement.`*⤶ ⤶ 6. Still in **Edit Mode**, select all bones with <key>A</key>⤶ 7. On the top-left of the viewport display, select **Pose** > **Animation** > **Bake Action**⤶ 8. Check the *"Visual Keying"* box > Check the *"Clear Constraints"* box > **Ok**⤶ 9. Export your animation⤶ ⤶ <upload src="a4aaf/8d907383c478151.png" size="151091" name="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⤶ ⤶ <upload src="a4aaf/8d907757d67845b.png" size="179777" name="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](https://en.wikipedia.org/wiki/Ball_(foot)#:~:text=The%20ball%20of%20the%20foot,serves%20mostly%20the%20same%20functions.) 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⤶ ⤶ <upload src="a4aaf/8d90778b0503050.png" size="311204" name="11.png" />⤶ *`Trace Height and Trace Radius are mostly fine with the default values`*⤶ ⤶ ---⤶ ⤶ # Stride Retargeting node in the AnimGraph Editor⤶ ⤶ 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 **<key>+</key>** 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⤶ ⤶ <upload src="a4aaf/8d90803d0f90e5a.png" size="40302" name="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⤶ ⤶ <upload src="a4aaf/8d908262157db31.png" size="46299" name="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:⤶ ⤶ <upload src="a4aaf/8d9082caa44f8fc.mp4" size="893964" name="huh.mp4" />⤶ *`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.`*⤶ ⤶ ---