Here is a query
I have a value that is linked to clock (eg 12.am is 0 and 11.59pm is 1). There are four stages of the days (split up into quarters/0.25).
I want to convert a range of that 0 - 1 (ie 0.25 - 0.5) into 0 and 1.
So as the clock counts through this range between 0.25 and 0.5, there will be a seperate counter that reads through 0 - 1 (and then resets when reaching the next stage).
I get the currentTimeOfDay with:
currentTimeOfDay += (Time.deltaTime / secondsInFullDay) ;
secondsInFullDay = 1440 at full range (and 1 at minimumand is adjustable (to speed the day up appropriately).
Everything works fine with the clock time, and I’ll probably figure it out before anyone replies, I’m just currently hurting my brain thinking about it. 
Here’s a generic formula to convert values from one range to another: Range Conversion: A Generic Approach - CodeProject
2 Likes
Fantastic, that’s just what I was looking for and it worked!
Cool. I don’t necessarily use a dedicated function to do this sort of formula, but it would be handy since I essentially have to do this same sort calculation any time I use Lerp or tween something.
Yeah, that link was great, it did the job perfectly, and is a quirky little routine if you want to pass it to something that requires old lerpy.
float UnitIntervalRange(float stageStartRange, float stageFinishRange, float newStartRange, float newFinishRange, float floatingValue)
{
float outRange = Mathf.Abs(newFinishRange - newStartRange);
float inRange = Mathf.Abs(stageFinishRange - stageStartRange);
float range = (outRange / inRange);
return (newStartRange + (range * (floatingValue - stageStartRange)));
}
2 Likes
By the by there’s a builtin function in Mathf that does this (but only if the range you are converting to is 0 to 1):
2 Likes