schteppe/p2.js

Calling World.step with timeSinceLastCalled === 0 produces undesired results

Grimeh opened this issue · 2 comments

Hi, I've run into an issue when trying to pause the game (by setting the global time scale to 0) will not pause the physics simulation as well (as desired) but instead make it revert back to the regular fixed time steps.

This is because World.step uses 0 as the timeSinceLastCalled default value, and therefore the value that indicates that the caller wants fixed time steps:

if(timeSinceLastCalled === 0){ // Fixed, simple stepping

I'm currently working around this by calling World.step like:

this.world.step(1 / 60, Math.max(dt, Number.EPSILON), this.maxSubSteps);

Preferably I would like to be able to call World.step with timeSinceLastCalled === 0, I think this could be accomplished by replacing

timeSinceLastCalled = timeSinceLastCalled || 0;

if(timeSinceLastCalled === 0){ // Fixed, simple stepping

with

if(timeSinceLastCalled === undefined){ // Fixed, simple stepping

Does that seem reasonable?

Yea, it sounds like good idea. I guess I didn't think of this case when I first wrote the code...

I've submitted a PR (#337) with the mentioned changes.