Fixing/adjusting root motion dynamically

visiblenoise

New member
What's the best way to adjust movement or rotation of an animation's root motion frame by frame as it's going?

In my particular case, I have turn-in-place animations that turns the character either 90 or 180 degrees, but I need to be able to have the character end up facing arbitrary directions. I thought to "intercept" the root motion rotation so that it would be set to zero if the character reached the desired direction before the animation finished (e.g. stopping rotation at 45' even though the 90' animation was playing). But from inside the Ability class I added for these animations, I'm not sure if it is possible to read the root motion deltas and optionally zero them if needed. Is it?

Obviously, stopping rotation abruptly while the rest of the animation still plays won't look that great, but it's the best workaround I could think of. If there's a way to get nicer results without elaborate animations, I'd really appreciate suggestions for that too.
 
The animation clips are only played as long as the corresponding animation state is active in the animator controller. So if your 90 degree takes 1s, and you play the animation only for 0.5s, the character should turn just 45 degree. You can set for instance the AbilityIntData animator parameter to enter/exit certain animation states.
 
Hmm, I hadn't thought of exiting the animation early. In this case since the root motion rotation isn't constant throughout the animation, I could monitor the current orientation from inside the Ability and stop itself accordingly. Worth a shot, thanks.

I'd still like to know if there's an easy way to massage root motion though - before trying to move to using UCC, I was reading and adjusting Animator.deltaPosition/deltaRotation values, using Animator.MatchTarget(), etc. It isn't clear how to plug that stuff into UCC.
 
The root motion data is written to CharacterLocomotion.AnimatorDeltaRotation and AnimatorDeltaPosition. There are public properties which you can use to adjust these values within the ability.
 
I must be missing something. As a test, I'm trying to force the rotation to be Quaternion.identity, expecting no rotation to happen while my ability is going:

Code:
public override void UpdateRotation() {
    m_CharacterLocomotion.AnimatorDeltaRotation = Quaternion.identity;
}

I also tried putting that line inside the ability's ApplyRotation(), Update(), and LateUpdate() - but the rotation was still happening normally.

However, I then tried setting it to something arbitrary (Quaternion.AngleAxis(1, Vector3.forward)) and was surprised to see it take effect. It seems like my setting AnimatorDeltaRotation and AnimatorDeltaPosition are only additive to the root motion, is that right? I don't see how to get at the original root motion deltas.
 
I recommend taking a look at CharacterLocomotion.OnAnimatorMove to see the implementation. UltimateCharacterLocomotion.OnAnimatorMove adds the animator deltaPosition/rotation.

But it is additive. You can get the original deltas from the Animator's deltaPosition/rotation.
 
Ah! Thanks for being patient with me. I was getting hung up on how the Animator doesn't seem to be accessible through the UCC classes, but it can be accessed simply through m_GameObject.GetComponent<Animator>().
 
Top