2 ms·
This happened to me, too. My guess is that the simulation stops running when not open, but when it next runs it computes using a time delta calculated by the ac
by tgb 10y ago
This happened to me, too. My guess is that the simulation stops running when not open, but when it next runs it computes using a time delta calculated by the actual time since the tab was seen. So the integration adds a ridiculous amount of acceleration to the velocity, at which point the whole thing is doomed. This problem: http://gafferongames.com/game-physics/fix-your-timestep/ http://gafferongames.com/game-physics/fix-your-timestep/
- grondilu 10y agoThat looks like a sensible explanation, thanks. I guess I can put a ceiling on dt as a quick work-around.
- throwanem 10y agoI bet you're right! Or close, anyway. From [1]: > The callback rate may be reduced to a lower rate when running in background tabs or in hidden <iframe>s in order to improve performance and battery life. [1] https://developer.mozilla.org/it/docs/Web/API/window/requestAnimationFrame https://developer.mozilla.org/it/docs/Web/API/window/request...
- jchavannes 10y agoYep. This is the code that's causing it[1]: var now = Date.now()/1000; var dt = now - then; Adding this line fixes it: dt = dt > 1 ? 1 : dt; [1] https://github.com/grondilu/grondilu.github.io/blob/47d41d/pendulum-simple.js#L53 https://github.com/grondilu/grondilu.github.io/blob/47d41d/p...