- Home /
How to make 2D Sprite Animation frames spread over the duration of the motion time
So, with Motion Time parameter on Animator state, you can set how long the duration of the said animation state will be.
GetComponent<Animator>().SetFloat("animDuration", 3f);
// would make the animation state last 3 seconds, if parameter is set in
However, if your animation is finished before that set Motion Time parameter, then your animation is finished before that time. I know it's because of exit time I have set up, but it made me realize that regardless of the animation's motion time, animation will play on its own and be over with it. Meaning, if motion time = 3 sec, animation time = 1 sec, there will be 2 seconds of idle time without animation during the remaining anim state duration.
Hmm.
What I want to do is spread the frames in the said animation and play them throughout the motion time parameter that is set up. Is there a way to do so?
I've tried:
GetComponent<Animator>().PlayInFixedTime("Base Layer.AnimBlend", -1, motionTime);
GetComponent<Animator>().Play("AnimBlend", 0, motionTime);
But those doesn't seem to work. I could do some math and
GetComponent<Animator>().speed = someVariable to make anim length == motion length;
But I was wondering if there's more direct solution to my issue. Thanks,