Skip to content

Commit

Permalink
Couple of World.step() proposals schteppe#392
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Yau committed May 28, 2021
1 parent 4e16d1b commit eccf0c2
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/world/World.js
Original file line number Diff line number Diff line change
Expand Up @@ -520,10 +520,8 @@ var step_tmp1 = new Vec3();
*/
World.prototype.step = function(dt, timeSinceLastCalled, maxSubSteps){
maxSubSteps = maxSubSteps || 10;
timeSinceLastCalled = timeSinceLastCalled || 0;

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

if(typeof timeSinceLastCalled === 'undefined'){ // Fixed, simple stepping
this.internalStep(dt);

// Increment time
Expand All @@ -540,7 +538,10 @@ World.prototype.step = function(dt, timeSinceLastCalled, maxSubSteps){
substeps++;
}

var t = (this.accumulator % dt) / dt;
// Get rid of excess simulation time
this.accumulator %= dt;

var t = this.accumulator / dt;
for(var j=0; j !== this.bodies.length; j++){
var b = this.bodies[j];
b.previousPosition.lerp(b.position, t, b.interpolatedPosition);
Expand Down

0 comments on commit eccf0c2

Please sign in to comment.