Dodges Lasting Slightly too Long

I tried this using some different animations, and each animation has a slightly different playback speed. When I go to dodge, The dodge seems to be slightly too long for the left and right dodges, and lasts an additional few seconds on the backstep dodge. I tried to set the dodge duration equal to the animator’s current animation’s clip length divided by that clip’s playback speed, but that doesn’t seem to fix the issue.

stateMachine.animator.GetCurrentAnimatorStateInfo(0).normalizedTime / stateMachine.animator.GetCurrentAnimatorStateInfo(0).speed

I also tried using that same value instead of using remainingDodgeTime -= deltaTime to check if we should be finished dodging.

if ((stateMachine.animator.GetCurrentAnimatorStateInfo(0).normalizedTime / stateMachine.animator.GetCurrentAnimatorStateInfo(0).speed) >= 1)
{
stateMachine.SwitchState(new PlayerTargetingState(stateMachine));
}

Does anyone have any recommendations?

Are you meaning that the animation stops and the dodge keeps moving?
Check to make sure that your dodge animations are set to looping = true.

Yes that’s right, sorry I didn’t explain that clearly enough.

I’ve since set my animations looping = true, but the issue persists.

If it’s helpful at all, I took a video. What’s a shame is that the forward dodge ( threw in a dodge roll ) seems to be fine in by book. But the other ones are still behind.

I took a closer look at this, and I think the most obvious solution is to scrap the remainingDodgeTime code altogether, and stick with the GetNormalizedTime…

        if (GetNormalizedTime(stateMachine.Animator, "Dodge") > .99f)
        {
            stateMachine.SwitchState(new PlayerTargetingState(stateMachine));
        }

Now the problem with this approach (and all approaches) is that we’re dealing with animations that don’t all have the same duration within a blend tree. If the animations don’t wind up with identical durations, then when one runs out sliding will occur…

While normally, I’m a huge fan of blend trees, this (and animation events!) are both issues with blend trees. One solution would be to very carefully calculate the speed of each animation so that they all equal exactly the same time.

It might make more sense to set up four dodge animation states and call the one that most corresponds to the direction. You can then select the best animation to use based on the DodgeInput:

        float forward = dodgingDirectionInput.y;
        float right = dodgingDirectionInput.x;
        if (Mathf.Abs(forward) > Mathf.Abs(right))
        {
            stateMachine.Animator.CrossFadeInFixedTime(forward<0?"DodgeRear":"DodgeForward", CrossFadeDuration);
        }
        else
        {
            stateMachine.Animator.CrossFadeInFixedTime(right<0?"DodgeLeft":"DodgeRight", CrossFadeDuration);
        }

Note that my earlier suggestion of setting the animations to loop was a bad one. It shouldn’t be looping.

Ah! The GetNormalizedTime function I bet will do it! Thanks Brian (also, noted, I’m unchecking loop now, thanks!)

Privacy & Terms