I’m working on a day/night cycle script, and I’m totally done except for the Color.Lerp
when 1 day/night cycle is set to 1 minute, the speed of the Color.Lerp is 0.004 it takes like 2-4 seconds
when cycle is set to 2 minutes color lerp is set to 0.002 (50%, with is good!)
but when i set the cycle to more than 10 minutes Color.Lerp isn’t really slow but it just doesn’t work
is this because unity cuts floats with more than 3 characters behind the comma
some code (Thats bassicly how i do it)
var CycleInMinutes = 12;
var Day : Color;
private var CurrentSkyColor : Color;
function Update () {
skycolor.camera.backgroundColor = CurrentSkyColor;
CurrentSkyColor = Color.Lerp(CurrentSkyColor,Day,Time.deltaTime * 0.004 / CycleInMinutes);
}
Post some code.. I have a feeling it's something else with how you're using the lerp.
i just tried it with Color.Lerp(CurrentSkyColor,Day,0.00016); and it DIDNT work so I'm still thinking that when i do SOO MUCH zeros behind the comma unity just does not do anything
Lerp (Color, Vector2, Vector3, etc) does something like this:
function Lerp (a, b, t) {
t = Mathf.Clamp01 (t);
return a * (1 - t) + b * t;
}
You are passing a very low value for t (running at 100 FPS and with CycleInMinutes = 10 the value would be 0.000004) so Lerp is always returning a value close to a. In fact if t is low enough it would return a due to rounding errors.
You should use fixed values for both a and b and do the math to span from 0 to 1 withing the specified time.
This will ONLY work if you start the cycle at the time the game starts.. using Time.time in this instance isn't such a good idea. His example he's transitioning from one color to another so in each update it takes the last update and applies the new lerp based on the delta time. In order to get that to work more closely to what you have mentioned here he'd need to record the startTime and subtract that from the current time to get the timeDifference since it started.. i.e. Color.Lerp(startColor, endColor, (Time.time - startTime) / (CycleInMinutes * 60.0));
Post some code.. I have a feeling it's something else with how you're using the lerp.
– Rod-Greenback on unity awnsers I'm going to post some code now!
– ChesleyI'm not sure if I understood correctly. Do you want to interpolate from CurrentSkyColor to Day in CycleInMinutes?
– luizgpayes thats kinda it and the 0.004 is there for the timing of the sunrise
– Chesleyi just tried it with Color.Lerp(CurrentSkyColor,Day,0.00016); and it DIDNT work so I'm still thinking that when i do SOO MUCH zeros behind the comma unity just does not do anything
– Chesley