Matter-js: Changing Time Scale Affects Physics

Created on 12 Oct 2016  路  9Comments  路  Source: liabru/matter-js

Changing engine.timing.timeScale significantly affects physics. (even for resting bodies)
It's well observable on the demo page when moving the timeScale slider.

I want to animate pausing the scene by gradually moving timeScale from 1 to 0 and from 0 to 1 on unpause but the change this causes to the physics is unbearable.
So I crestfallenly went to just toggle timeScale between 1 and 0.

After fixing the weird gravity behavior I experienced I came to notice that even with toggling timeScale as described there are errors in simulation.

After pausing+unpausing the scene that way a quick look shows me the following:

  • a stack of resting rects will bounce
  • all bodies will lose all momentum and drop straight down

I found these discussions which seem related to me:

  • #148
  • #280
  • #240

As I investigated I got the impression that values from the previous update call get used which would explain why incorrectnesses build up as you _time-scale_ the simulation.

This pretty much renders varying time-scaling/slow-mo useless...

investigate

Most helpful comment

To my knowledge, no. This was a blocker for me and I won't do another project with matter-js until this was fixed.
I even could have lived without time-scaling, but low FPS have the same effect.

All 9 comments

It seems like the same effects occur when the frame rate is low and the engine tries to correct the lag.

Running my simulation on the phone bodies sink into each other towards gravity and stretch back to where they should be after a few seconds just to start sinking again.
It looks like the engine is breathing. o_O

I have noticed this issue too, it seems that the only timestep that calculates correct physics is 1/60th of a second.

I hope this gets looked into, it'd be really great to use this time scaling feature reliably when applying the same forces at the same time step.

Confirmed.
At this point the "slo-mo" effect doesn't work at all when forces are applied to time-scaled bodies.
In my case it is the Body.setVelocity() that makes bodies misbehave
Would love to see this fixed.

I'm having the same issue. My evolutionary algorithm needs a way to speed up the simulations when evaluating the fitness of individuals in the population - the physics changes, when increasing the timescale, stops this.

Is there a way around this? like making the simulation near instant?

To my knowledge, no. This was a blocker for me and I won't do another project with matter-js until this was fixed.
I even could have lived without time-scaling, but low FPS have the same effect.

I was able to get it working by just increasing the speed of the game loop:

setInterval(function() { Engine.update(engine, 1000 / 60); }, 1000 / 60);

Beware that the issue will likely resurface for you when your simulation becomes too extensive to run the speed-up in realtime, @Nathan-Devery.

Any updates on this?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Zhaopengyang picture Zhaopengyang  路  3Comments

mrspeaker picture mrspeaker  路  3Comments

TimuJiang picture TimuJiang  路  4Comments

253153 picture 253153  路  3Comments

maximilianberndt picture maximilianberndt  路  4Comments