简体   繁体   中英

Lerp not working as expected, jumps to value instead of smoothly proceeding to it over time

Good Day,

I am working on a game and, when a certain conditions is reached I want to increase the number of particles spawned. Now instead of them just appearing all at once I elected to use lerp so that they will smoothly roll up to that value.

However despite trying my best I still cannot get this to occur smoothly and it's jumping to the maximum way too soon. I've posted my code with the hopes of someone pointing out the error in my ways.

void Update () {
    if (increaseLeaf==true)
    {

        var main = LeafStormParticleSystem.main;
        Debug.Log("here");
        main.maxParticles = (int)Mathf.Lerp(5, 150, counter);
        main.simulationSpeed = (int)Mathf.Lerp(1, 5, counter );
         counter += Time.deltaTime / 2;

        if (main.simulationSpeed == 5)
        {
            increaseLeaf = false;
        }
    }
    //counter += Time.deltaTime / 2;
    if (decreaseLeaf == true)
    {
        var main = LeafStormParticleSystem.main;

        main.maxParticles = (int)Mathf.Lerp(150, 5, decounter);
        main.simulationSpeed = (int)Mathf.Lerp(5, 1, decounter);
        decounter += Time.deltaTime / 2;

        if (main.maxParticles == 5)
        {
            decreaseLeaf = false;
        }
    }
}

当您使用lerp()时,您可以执行以下操作var num = new var(lerp(a,b));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM