w0rm/elm-physics

Model state seems to miracliously change in the Dominoes Demo

PixelPartner opened this issue · 1 comments

I played with the Dominoes demo and left it in this state:

  • Run on Windows 10, Firefox
  • changed to wireframe, center of mass visible
  • run

an hour later, the fallen dominos have wandered / rotated to a totally different place.

So there seems to be a tiny drift that accumulates after a long time.

How about a global flag that freezes the sim and is reset by any plausible state change?

w0rm commented

The dominoes are made so that there is not much friction so that they can slide along each other. To ensure that things stop, one could probably use damping.

Another possibility is to measure velocities of all objects and stop the simulation, but build this outside elm-physics. I guess this is what you propose as a global flag? This is what I am doing in elm-pool to determine if things have stopped moving: https://github.com/w0rm/elm-pool/blob/adb6f68234c568d1eb30cad3c6d3158fd7c15655/src/Game.elm#L736 I am not sure I would like to introduce this to this example though, because it will make it unnecessary complex.

Maybe in the long term we could implement the "sleeping state" for bodies, that withdraws a body from simulation if the movement is below the certain threshold for several frames, until further collisions or applied forces wake it up. This is a bit difficult to add, but could be worth it to also improve the performance.