0
\$\begingroup\$

I'm trying to implement time line objects, the purpose of those would be to issue events at specific times. When and what is specified through objects called units, which is what you attach in the time line.

Got two types of time units, Action and Transit. Action counts to the end of the time unit, then issue whatever event with provided values intact.

My problem is Transit, which, frame by frame, modifies provided value(s) by multiplying time ratio before issuing the event.

I calculate ratio as: (in pseudo code)

ratio = (counter += delta time) / unit end time

My issue is that I keep getting either different results, or unbalanced progress, like adding 90% of the value quick then the last 10% of value at a much slower phase.

I've tried something like (in pseudo code) so far:

delta value = (end value - earlier delta values) * ratio

for each new frame.

Not sure how to put this together, so could really use a few pointers on this. Hope I made myself clear.

PS. I'm doing this in JavaScript, I know JS isn't the most accurate language when it comes to precision numbers, but it should be able to handle something like this.

Thank you in advance.

\$\endgroup\$
2
\$\begingroup\$

Considering how the ratio is calculated, the culprit seems to be the delta time (time step). It is the only variable that depends on unknown factors in the context of the calculation.

The issue described is likely caused by a variable time step. In that case, the counter would not increment uniformly, but faster or slower depending on arbitrary conditions.

A fixed time step should provide you with the behaviour you're looking for. Then the counter increments would always occur at the same rate.

\$\endgroup\$
  • \$\begingroup\$ Hello and thank you for answering. Yes, the delta time vary from frame to frame, I think that's important to take into consideration to get as "dependable values" as possible over time. I managed to figure this out, will answer in a sec. \$\endgroup\$ – MetalGodwin Oct 30 '16 at 20:54
0
\$\begingroup\$

I managed to figure it out. I wasn't supposed to keep track of already applied delta times, but applied ratios.

Pseudo code.

ratio = (counter += delta time) / transition end time

if(ratio > 1)
    ratio = 1

ratio -= ratios
ratios += ratio

result = value * ratio

Even after 20+ subsequent 1000ms transitions which increase the same value, the result values offset was less than .0001 against expected, so I'm satisfied with this.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.