In this lesson, you will learn how to stabilize your character’s feet on uneven terrain by layering procedural IK adjustments on top of your Motion Matching animation data.
The Challenge of Motion Matching
When using Motion Matching, your character's poses are pulled from a database to match your desired movement trajectory. While these poses are high-quality, they are often "baked" for flat ground. If your character walks over a slope or a rock, the feet might float in the air or clip into the geometry because the animation doesn't know about the surface directly beneath it.
Implementing Procedural Foot Locking
To fix this, we use Foot IK as a post-process effect in your Animation Blueprint. Instead of modifying the animation source, we treat the feet as "IK targets" that calculate their position based on the floor's collision.
- Trace the Ground: Use a
LineTraceByChannelorSphereTracestarting from a few centimeters above the foot bone, pointing downward. - Calculate the Offset: Find the distance between your trace hit location and the floor, then determine how much you need to adjust the foot bone's Z-axis to "lock" it to that surface.
- Apply IK: Use a
Two Bone IKnode or the built-inLeg IKnode within your AnimGraph. By setting theEffector Locationto the hit point found in your trace, you force the foot to stay planted regardless of the animation's current pose.
// Logic concept for a Foot IK adjustment
float TraceOffset = HitResult.ImpactPoint.Z - FootBoneLocation.Z;
// Apply this offset to the Foot IK Effector in the AnimGraph
// Ensure you use a smoothing Interp node to avoid twitching!
Smoothing the Transition
Since Motion Matching is dynamic, the IK targets might change rapidly. To prevent the feet from "jittering," always wrap your IK offset calculations in an FInterpTo or a similar smoothing function. This ensures that as the character moves from a flat surface onto a slope, the IK adjustments blend in over a few frames, keeping the character movement grounded and believable.
Key Takeaway: Procedural Foot IK serves as a secondary layer that corrects the spatial position of feet hit by your environment traces, ensuring your Motion Matching output remains firmly grounded on any terrain.