1

I want to lerp the start color of two particle systems from one color to another in Unity if the player enters a triggerzone. I tried to do it with Color.Lerp but the result is that it lerps "laggy", meaning it has only 3 colors inbetween. My code:

public IEnumerator animateTriggerEnter(float duration = 0.1f)
{
    float elapsedTime = 0f;
    float lerp = 0f;
    while (lerp <= 1f)
    {
        elapsedTime += Time.deltaTime;
        lerp = elapsedTime / (float) duration;
        topParticle.startColor = Color.Lerp(standardColor, triggerColor, lerp);
        botParticle.startColor = Color.Lerp(standardColor, triggerColor, lerp);
        yield return null;
    }
}

For the value lerp, I always get the same 6 values, but should it not be more? It also remains laggy with a higher duration.

andeart
  • 935
  • 6
  • 19
KonfuPanda
  • 17
  • 4
  • can you simply try it with a long duration (say 3f) and see what happens? – Fattie Feb 21 '16 at 15:52
  • It does not change. Still just rough transitions from one color to another just with longer duration between each transition. – KonfuPanda Feb 21 '16 at 16:05
  • I can circumvent this problem if the particle system has got the color over lifetime option enabled with the default setting. – KonfuPanda Feb 21 '16 at 16:11
  • I just recreated this setting and it works perfectly fine. Are you messing with `Time.timeScale` anywhere in your code? Could you post a screenshot of your particle-system settings please? – andeart Feb 22 '16 at 19:42

1 Answers1

0

First of all I'd try isolating

Color.Lerp(standardColor, triggerColor, lerp);

and testing it's speed Stopwatch? If I am right lerp is noting more than

result=startValue + (endValue - startValue) * lerpValue;

In that case + 1 constructor execution. According to MSDN math itself will should take less than

lerp = elapsedTime / (float) duration;

Are you sure it's lerp problem?

dnkira
  • 362
  • 3
  • 8
  • I'm fairly certain it's *not* a lerp problem. OP believed it to be so (and in reality, it could be), but it's fine in any case. That said, your post doesn't attempt to answer the question in any manner, and suggestions like these should usually go in the comments. Cheers! :) – andeart Feb 22 '16 at 19:46