Playing part of animation

Hello everyone!

I need to make this functionality:

  1. We have hero object with animator in it. We need to play animation part-by-part following ingame progression.
  2. Problem is, that dividing of animations must be done dynamically (e.g. in one case we need to divide animation into 3 parts, in other - into 6 parts)
  3. Main functionality must be like this:
    0% progress - animation didn’t played at all
    33% progress - animation is played from 0% to 33% and then stopped at 33%
    66% progress - animation is played from 33% to 66% and stopped at 66%
    100% progress - animation is played from 66% to 100% and finished

Are there any options to make it possible?

you can use

public void CrossFade(string stateName, float normalizedTransitionDuration, int layer = -1, float normalizedTimeOffset = float.NegativeInfinity, float normalizedTransitionTime = 0.0f);

but if you want crossfade to self, I think you’ll need CrossFadeInFixedTime

Unfortunately, it doesn’t work.

I have animation with total 150 frames in it. I want to use only 93 frames of it
I am calculating progress of animation here:
var pro = (1f / 150) * (93/100f) * progress; (progress is percentage of animation, that need to be played)

Tried 2 variations:
_animator.CrossFadeInFixedTime(“Shooting”, pro, 0, pro, 0.0f);

and

_animator.CrossFadeInFixedTime(“Shooting”, CalculateFrameTime(pro));
private float CalculateFrameTime(float frame)
{
float frameTime = 1f / 60;

return frame * frameTime;
}

Both did the same: it just plays animation fully (starting from different time (pro value)
But I need to play animation from previous progress value to new one (e.g. from 0% to 20%, then 20% to 40%…)

don’t have time now but
_animator.CrossFadeInFixedTime(“Shooting”, pro, 0, pro, 0.0f);

should be
_animator.CrossFadeInFixedTime(“Shooting”, 0.2f, 0, pro);
I think you can leave out the last value


fixedTimeOffset The time of the state (in seconds).
normalizedTransitionTime The time of the transition (normalized).

I think the first one is where the animation crossfade starts, the second one is the time of the state where it crossfades to

I don’t think that CrossFade methods applicable for my problem. I need to play animation part-by-part depending on external progress variable. No needed to make transitions etc

if you just play animation parts, it will be jerky (there are no frames in the animation when playing, just normalizedtime, the “frames” are calculated from curves at a given update rate)

I’m pretty sure crossfades can do that

of course you need to track the state and the normalizedtime