Hacker News new | past | comments | ask | show | jobs | submit login

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/



Yep. 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/p...


I 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/request...


That looks like a sensible explanation, thanks. I guess I can put a ceiling on dt as a quick work-around.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: