Slowing down the light intensity on Campfire free asset

Completely new to C# and having a little trouble solving this small problem.

I’m using the Campfire asset by David Stensfors, while it looks great the “light flicker” effect is really fast and I want to slow it down.

The original script:

using UnityEngine;

public class FireLightScript : MonoBehaviour
{
    public float minIntensity = 0.25f;
    public float maxIntensity = 0.5f;
   

    public Light fireLight;

    float random;

    void Update()
    {
        random = Random.Range(0.0f, 150.0f);
        float noise = Mathf.PerlinNoise(random, Time.time);
        fireLight.GetComponent<Light>().intensity = Mathf.Lerp(minIntensity, maxIntensity, noise);
    }
}

So I want to slow it down to more of a pulse than a flicker and I guess i have to modify “Time.time” somehow.

using UnityEngine;

public class FireLightScript : MonoBehaviour
{
    public float minIntensity = 0.25f;
    public float maxIntensity = 0.5f;
    public float flicker = 0.5f;

    public Light fireLight;

    float random;

    void Update()
    {
        random = Random.Range(0.0f, 150.0f);
        float noise = Mathf.PerlinNoise(random, Time.time * flicker);
        fireLight.GetComponent<Light>().intensity = Mathf.Lerp(minIntensity, maxIntensity, noise);
    }
}

I tried this but doesn’t seem to really do anything. Any tips on how to achieve my objective?

I can’t be sure if this is what you wanted… and I do not know how the asset/light works in that project. :slight_smile:
However, I made a simple test with a light and a cube with the code you posted.
I changed Update to a regular method, i called it “LightUp” … and in Start() , I used InvokeRepeating
Tested a few values, like: .5f and .25f and .35f
In case that is something you’re looking for.
If I misunderstood the question, sorry :slight_smile:

Multiply noise by flicker. What you’re doing is changing the range of values that can be selected on the Perlin graph/sheet/whatever (Perlin Noise is basically selecting a random value from a “texture” of noise vectors). What you want to do is slow down the rate at which the flicker happens, which means you have to modify the lerp value.

The final parameter in Mathf.Lerp is t, which factors into this equation: Output = (1 - t) * Input1 + t * Input2 In actuality what this does is return a value t * 100% of the way from Input1 to Input2, so if t is smaller, it’ll move less quickly and be harder to notice. Math is fun!

Hmm ok. I think I see what you are saying but still not sure how to apply this to the sample code?

On line 18, change fireLight.GetComponent<Light>().intensity = Mathf.Lerp(minIntensity, maxIntensity, noise); to fireLight.GetComponent<Light>().intensity = Mathf.Lerp(minIntensity, maxIntensity, noise * flicker);

Also, you may want to call GetComponent() on fireLight in the Start() function and cache it as a variable, for the sake of good practices.