Search Unity

Question Playing part of animation

Discussion in 'Animation' started by valentin-shemchuk, Jun 20, 2021.

  1. valentin-shemchuk

    valentin-shemchuk

    Joined:
    Jul 13, 2018
    Posts:
    5
    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?
     
  2. bobadi

    bobadi

    Joined:
    Jan 3, 2019
    Posts:
    674
  3. valentin-shemchuk

    valentin-shemchuk

    Joined:
    Jul 13, 2018
    Posts:
    5
    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%....)
     
    Last edited: Jun 24, 2021
  4. bobadi

    bobadi

    Joined:
    Jan 3, 2019
    Posts:
    674
    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
     
  5. valentin-shemchuk

    valentin-shemchuk

    Joined:
    Jul 13, 2018
    Posts:
    5
    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
     
  6. bobadi

    bobadi

    Joined:
    Jan 3, 2019
    Posts:
    674