Finding normalized value of divided number
hey all,
have come to a road block and could really do with some help, so any would be appreciated and thanks before hand.
Now how to explain this
looking at this really awesome best drawing in the world how would i go about finding a value on the green line if i supply the hour and minute of the hour?
thanks for any help
Answer by UnityCoach · Sep 14, 2017 at 11:57 AM
I understand you want to implement some clock system.
I would probably organise everything in minutes to make things simpler.
As you know there's 1440 minutes in 24 hours, you can do a Lerp, or InverseLerp over 0 to 1440.
Like, say you want to provide 19h30, you would do
float t = Mathf.InverseLerp (0, 1440, 19*60+30);
t would then hold the normalised value of 19h30 over 24hrs.
I'm not sure this is what you're looking for. Please tell us more if this doesn't help.
Answer by danipren · Sep 14, 2017 at 12:21 PM
Thanks so much for your reply and help but im still not sure, i think that would give me the blue line normalized. Maybe i explained poorly or maybe im just being really stupid;
i kinda have it working but unreliable and only updates on the hour doesnt take into account the min and i dont think this is proper at all and would really like to get it down to minute or seconds level control
h is the hour as an int.
float t = Mathf.Repeat((h / 24) * TODGroups[0].timeSettings.Count + 0.5f, 1);
hour -= 1;
if(t == 0 )
{
t = 0.99f;
if(hour == 3)
{
t = 0.01f;
}
}
if(hour < 0)
{
hour = TODGroups[0].timeSettings.Count - 1;
}
int nextHour = hour + 1;
if(nextHour > TODGroups[0].timeSettings.Count - 1)
{
nextHour = 0;
}
Your answer
Follow this Question
Related Questions
I keep getting the 'Unexpected Symbol' error but cant find whats wrong with code 1 Answer
Script continues after it has been destroyed 0 Answers
Error CS0177 - "GameManager does not contain a definition for 'GetPlayer' PLEASE HELP! 0 Answers
Transform.position returns strange position 1 Answer
Gameobject Gravity 2D Script 0 Answers