# lame equation

This topic is 1093 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I want to set my day change every x minutes (lets say its 7 minutes) (new day every x minutes)

lets say i have a float that tells me which time of day i currently am like

float time;

starting from 0.0 to 24.0

time = 5.9; means hour 5 minute 0.9*60 -> 5:54

now i need somehow to find a constant that i will add every frame so after x minutes it time will reach 24.0 (starting from 0.0)

you know

dt = time_between_frames;

time = time + dt*time_between_frames; // or sth like this.

so how do i calculate this D: ??

##### Share on other sites

By linear interpolation.  (input and output grow at the same rate, 2*dt -> 2* longer game time)

Your input is real-world minutes (RM) (you didn't say the unit of frame time, I assume it's minutes, just like x. If you want a different unit you can do the same calculation again, but with slightly different numbers.

0 RM = 0 GH     [1]

x RM = 24 GH   [2]

Linear interpolation:    GH = a * RM + b [3]

[1] in [3]: 0 = a * 0 + b    --> b = 0

[2] in [3]: 24 = a * x + b  --> a = 24 / x (since b == 0)

Thus GH = 24 * RM / x

##### Share on other sites

ah yes forgot to tell that time_between_frames is in seconds.

and i really dont get that:

Linear interpolation:    GH = a * RM + b [3]

[1] in [3]: 0 = a * 0 + b    --> b = 0

[2] in [3]: 24 = a * x + b  --> a = 24 / x (since b == 0)

Thus GH = 24 * RM / x

what is b [3] what is [3] what oius [1] [2] what is x what is b what is a ?

Edited by WiredCat

##### Share on other sites

what is b [3] what is [3] what oius [1] [2] what is x what is b what is a ?

Alberth is just giving the equations names/reference so he can say 'substitute equation 1 into equation 3' and so on.

This is pretty much the same as what Alberth does:

At 0 hours, real seconds is also 0

At 24 hours then real seconds is 7*60 (this is from you saying 1 day is 7 minutes)

Then straight line/linear equations

y = mx+c (just as Alberth has done)

y is going to be 'game hours', x is 'real seconds'. We need to work out m and c.

We have 2 unknowns so we need 2 equations, luckily we have 2 'pairs' of values so we can make 2 equations.

when x is 0, y is 0 as we showed above thus 0=0*m + c => c is 0.

Now we put in the end of day values:

24=m*(7*60); c has gone since it was just 0. Rearrange to find m

m = 24/(7*60)

Now you have c and m values you can transform from 'real seconds' into 'game hours'. If a frame takes 0.017 seconds (approx 60fps) then the amount to add to your 'game hours' will be:

m*0.017+c = 0.0097

If you start at 'game time' 0 and the frame takes all of 7 minutes (ouch) then:

m*(60*7)+c = 24

Which makes sense since the whole day will have passed. Or 3.5 minutes (half your in game time)

m*(60*3.5) = 12, half a day.

Edited by Nanoha

##### Share on other sites

is this equation good?

v - velocity of the time change
s - distance - 24
t - time in minutes

v = s / t

v = 24 / min; //min = 10

v = 2.4;

ahue = ( v / 60.0 ) - since 1 minute = 60 secs

time = time + ahue*time_betwee_frames;
Edited by WiredCat

##### Share on other sites

realSecondsPerGameDay = 7*60;

m = 24/realSecondsPerGameDay;

time = time + m*timeBetweenFrames;

'm' can be calculated before hand. Assumes timeBetweenFrames is in seconds. If you want a day to take 10 minutes instead then realSecondsPerGameDay = 10*60 etc.

Edit: Your equation seems fine. I got confused first with the - symbols, I thought it was part of it but now I realise they are not. What you are doing is correct.

Edited by Nanoha

##### Share on other sites

yeah but i see that ( v = s / t ) / 60.0 == v = s / (t*60.0);  and i can't compare how is that possible.

##### Share on other sites

They are the same, consider this:

a = (b/c)/d, multiply both sides by d

a*d = b/c, multiply both sides by c

a*c*d = b, now divide both sides by c*d

a = b/(c*d)

Thus:

(b/c)/d == b/(c*d)

Same thing with our equations, it might seem unintuitive but they are the same.

Edited by Nanoha

1. 1
2. 2
Rutin
20
3. 3
khawk
17
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 44
• ### Forum Statistics

• Total Topics
633759
• Total Posts
3013720
×