Hi all,
I’m working on a day/night cycle script after watching some Youtube tutorials and reading a little bit. All is working well so far, you can see from my code snippet below, there’s a time of day which goes from 0.0f to 1.0f. Up to middday, the sun increases in brightness from 0 to 1 nicely using Mathf.Lerp.
However I’m struggling to get my head around how I get the intensity to go the other way (decrease) once the midpoint 0.5f has been passed.
// If it is morning..
if (currentTimeOfDay < 0.5)
{
sun.intensity = Mathf.Lerp(0, 1, currentTimeOfDay * 2);
}
// If it is afternoon/evening...
if (currentTimeOfDay >= 0.5)
{
sun.intensity = Mathf.Lerp(1, 0, currentTimeOfDay);
}
With my code above, the sun intensity “snaps” from 1 at midday to 0.5 immediately (due to how the Mathf.Lerp is working there obviously).
How can I have the intensity lerp from 1 to 0 based on the time of day 0.5 → 1.0 range?
Any thoughts?
Thanks in advance everyone.