Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Grimeh opened this issue Sep 27, 2018 · 2 comments
Open

Comments

@Grimeh
Copy link

Grimeh commented Sep 27, 2018

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?

@schteppe
Copy link
Owner

schteppe commented Oct 7, 2018

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

Grimeh added a commit to Grimeh/p2.js that referenced this issue Oct 17, 2018
Calling World.step with a `timeSinceLastCalled` of 0 would cause it to revert
to the fixed time step behaviour. This was due to the default value of
`timeSinceLastCalled` being 0. This change checks for `undefined`, as opposed
to 0.

See issue schteppe#334 for more details.
@Grimeh
Copy link
Author

Grimeh commented Oct 17, 2018

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

jramstedt pushed a commit to jramstedt/p2.js that referenced this issue Aug 28, 2019
Calling World.step with a `timeSinceLastCalled` of 0 would cause it to revert
to the fixed time step behaviour. This was due to the default value of
`timeSinceLastCalled` being 0. This change checks for `undefined`, as opposed
to 0.

See issue schteppe#334 for more details.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants