Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Overshoot for scale function

Discussion in 'Scripting' started by stobak, Jan 31, 2020.

  1. stobak

    stobak

    Joined:
    Dec 9, 2016
    Posts:
    16
    Hello! I'm looking for a way to replicate the overshoot effect shown in this video

    My intention is to have a player game object increase in size using this effect as he grows larger.

    I've Googled around and the recommendation is to use a Lerp or SmoothDamp function to replicate the effect. I've watched some Youtube videos that cover both functions, but the interpolation the authors use always seem to be a smooth transition from one point to another. I've yet to see an example that gives me that "bounce" effect. Is there something I'm missing? would anyone be able to provide me with examples on how to achieve this?

    Thanks in advance!
     
  2. greasemonkeyandy

    greasemonkeyandy

    Joined:
    Apr 16, 2019
    Posts:
    1
    overshoot generally uses quadratic curves (which is not the same as linear), you will likely need a good tween library or write your own.
    the other option is to use the in built animator and set it to a curve.

    here is a good write up on tweens: https://kodi.wiki/view/Tweeners
     
  3. stobak

    stobak

    Joined:
    Dec 9, 2016
    Posts:
    16

    Thanks for the insight! I'm looking at some different tween libraries now. At least there's no shortage of them.
     
  4. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,886
    Check out these easings. https://easings.net/en

    You can just use
    public AnimationCurve easing
    and make whatever shape you want, then use Evaluate between 0-1.

    Example:
    Code (csharp):
    1. public AnimationCurve curve;
    2. float speed = 1f;
    3. float anim;
    4.  
    5. void Update()
    6. {
    7.     anim += speed * Time.deltaTime;
    8.     transform.localScale *= curve.Evaluate(anim);
    9.  
    10.     if (anim > 1f) anim = 0;
    11. }
     
    stobak likes this.