Animator normalized time issue

Hello i have i weird issue when am trying to get the current animation normalized time its never correct

private float CalculateNormalizedTime()
    {
        AnimatorStateInfo currentStateInfo = stateMachine.Animator.GetCurrentAnimatorStateInfo(0);
        AnimatorStateInfo nextStateInfo = stateMachine.Animator.GetNextAnimatorStateInfo(0);

        if (stateMachine.Animator.IsInTransition(0) && nextStateInfo.IsTag("Attack"))
        {
            Debug.Log("in transtion: next " + nextStateInfo.normalizedTime +" current " + currentStateInfo.normalizedTime);
            return nextStateInfo.normalizedTime;
        }
        else if (!stateMachine.Animator.IsInTransition(0) && nextStateInfo.IsTag("Attack"))
        {
            Debug.Log("not transtion " + nextStateInfo.normalizedTime);
            return currentStateInfo.normalizedTime;
        }
        else return 0;

    }

debugging values for the last animation noramllized time 0.039 and the current is .69

What do you expect it to be? What makes you say it is incorrect?

I think the issue is that it stops at .69 current/.398 next once the current is done it falls out of the check
I suspect it’s the 2nd check that is the root of the issue:

At this point, if the Animator is no longer in transition, then we’re interested in currentStateInfo.IsTag, not nextStateInfo.IsTag, because at this point we no longer have a transition, we’re fully in the next state.

else if (!stateMachine.Animator.IsInTransition(0) && currentStateInfo.IsTag("Attack"))

@Kizaro1 I edited the formatting so that the picture showed. Make sure that the ``` appears on it’s own line with nothing else on it at the end of a code block.

1 Like

ty it was really the problem i didnt notice :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms