Search Unity

  1. Click here to see what's on sale for the "Best of Super Sale" on the Asset Store
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

How to add a "fake" dampening after scrubbing through AnimationClip

Discussion in 'Animation' started by alphakanal, Oct 26, 2020.

  1. alphakanal

    alphakanal

    Joined:
    Jan 21, 2013
    Posts:
    52
    Hi!

    I'm scrubbing through a Animation with my MouseWheel and using this code attached to the animated Object:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class ControlAnimation : MonoBehaviour
    6. {
    7.     public float speed = 0.01f;
    8.  
    9.     private Animator anim;
    10.     private float animPos = 0;
    11.  
    12.     void Start()
    13.     {
    14.         anim = GetComponent<Animator>();
    15.         anim.speed = 0;
    16.     }
    17.     void Update()
    18.     {
    19.         if (Input.mouseScrollDelta.y > 0 && animPos < 1)
    20.         {      
    21.             animPos = animPos + speed;
    22.                }
    23.         if (Input.mouseScrollDelta.y < 0 && animPos > 0)
    24.         {
    25.             animPos = animPos - speed;
    26.                }
    27.         anim.Play("MainAnimationClip", -1, animPos);
    28.     }
    29. }
    This is working fine BUT:
    The animation is stopping immediately when stop scrolling the mouse-wheel.

    Now i'm trying to add some kind of dampening to the animation so it's "fading out" instead of stopping immediately. Guess using lerp would be the right tool - but no idea how to use it in this case :D

    Any idea how to add such a dampening to this ?

    Thanks in advance & stay healthy
     
    Last edited: Oct 26, 2020
unityunity