How to find the normalised time of a looping animation?

I have an axe chopping animation. I need the tree health to be reduced at a certain point in the animation. The problem is that the normalised time does not start from 0 when one loop of the animation is complete. Rather, it continues increasing indefinitely rendering this code:

public void ChopStatesFSM()
    {
        switch(chopStates)
        {
            case ChopStates.triggerChop:
                    unit.animator.SetBool("Chop", true);
                    chopStates = ChopStates.hitTree;
                break;
            case ChopStates.hitTree:
                if (unit.animator.GetCurrentAnimatorStateInfo(0).IsName("Chop"))
                {
                    if (unit.animator.GetCurrentAnimatorStateInfo(0).normalizedTime >= .3f &&
                        unit.animator.GetCurrentAnimatorStateInfo(0).normalizedTime <= .4f)
                    {
                        Debug.Log("hit tree");
                    }
                }
                break;
        }
    }

useless. Any hints would be appreciated :slight_smile:

I’ve tried using triggers instead and just restarting the animation but, due to the transition with idle, it looked awful. The legacy system was so much better at stuff like this!!!

From Unity - Scripting API: AnimatorStateInfo.normalizedTime :

The integer part is the number of time a state has been looped. The fractional part is the % (0-1) of progress in the current loop.

So if I understand you correctly, you could just do

float normalizedTime = unit.animator.GetCurrentAnimatorStateInfo(0).normalizedTime;
float normalizedTimeInCurrentLoop = normalizedTime - Mathf.Floor(normalizedTime);

to get your numbers and then check if 0.3f <= normalizedTimeInCurrentLoop <= 0.4f

But I feel like checking if that way seems like a bad idea and this is rather exactly what animation events are created for - as you already note yourself. I can’t quite follow your point when you say

events, while great, are limited in terms of the kinds of methods you can use.

If you explain more, maybe we can help you out using events in a better way?