Math.Lerp stuck at one value and not moving

Hello, can somebody please tell me why it gets stuck un the first value. so i have this custom shader and i want it to fade out (which is basicly changing the opacity of the rim color which is named: “_Scale”) but it works kind of strange… so instead of fading out it does nothing but shows me one value and no animation whatsoever. However if I change the speed its becomes more transparent when I press play (NO ANIMATION JUST MORE TRANSPARENT) and just stays there. No idea why this is happeneing.

Code:

    Renderer rend;
    // Use this for initialization
    void Start () {
    rend = GetComponent<Renderer>();
        rend.material.shader = Shader.Find ("FresnelPack/Transparent Rim Unlit");
        rend.material.SetFloat ("_Scale", Mathf.Lerp (0.8f, 0f, Time.deltaTime * 40));
    }

Lerp isn’t a magic function that does stuff over time, it’s a basic math function that returns a value immediately, like all other math functions. You’re only calling it once; if you want to use it for animation, you need to call it repeatedly while advancing the third parameter from 0 to 1. Can someone explain how using Time.deltaTime as 't' in a lerp actually works? - Questions & Answers - Unity Discussions

–Eric

You may also want to read this fine article.

1 Like

Why do you just use something like:

Vector3.MoveTowards(0.8f, 0f, Time.deltaTime * 40);

Unity - Scripting API: Vector3.MoveTowards ?

Because that’s not the issue; MoveTowards is still a basic math function that returns a value immediately and doesn’t animate over time. You need to call it repeatedly for it to work.

–Eric