Implementing Look-At Logic in Motion Matching
In this lesson, you will learn how to layer procedural look-at offsets over motion-matched animations to keep your character focused on a target without breaking the fluidity of their locomotion.
Why Motion Matching Needs Help with Focus
Motion Matching is exceptional at selecting the most natural-looking animation based on your character’s trajectory. However, because it relies on existing animation data, it can’t inherently "look" at a specific moving object if that movement wasn't captured in your database. If you simply rotate the head bone to a target, the sudden movement will clash with the high-fidelity locomotion, creating a "snapping" or jittery effect.
The Procedural Layering Approach
To solve this, we use a Layered Blend per Bone or a dedicated Look-At node within your AnimGraph, but we must process it after the Motion Matching node. The secret to maintaining the flow is to apply the rotation offset using Inertialization or a gentle alpha interpolation.
Instead of snapping the bone directly to the target, we calculate the FindLookAtRotation from the character’s head to the target. We then pass this rotation into a transform modification node. The key is to blend the weight of this rotation based on the character’s current state.
// In your AnimGraph logic, you would drive the "Alpha" of the Look-At
// node based on the character's movement intensity.
float CalculateLookAtAlpha(float Velocity) {
// Reduce focus when running, increase when standing still
return FMath::Clamp(1.0f - (Velocity / MaxWalkSpeed), 0.0f, 1.0f);
}
Best Practices for Stability
- Bone Constraints: Always define limits on how far the neck and head bones can rotate to prevent the mesh from deforming unnaturally.
- Smooth Interp: Never set the rotation value instantly. Use
FMath::RInterpToto allow the head to track the target with a slight, realistic delay. - Hierarchy: Apply the look-at logic after your Inertialization node. This ensures that the look-at pose is treated as a final, additive layer rather than part of the pose selection process itself.
Key Takeaway: To maintain natural locomotion, treat look-at logic as an additive, alpha-blended procedural layer applied after the Motion Matching pose selection, ensuring head movement respects the underlying body momentum.