Skip to content

Commit

Permalink
Limit the accumulator and allow dt of 0, from schteppe#392
Browse files Browse the repository at this point in the history
  • Loading branch information
marcofugaro committed Jun 27, 2020
1 parent 157d9b3 commit 2970232
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/world/World.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,8 @@ export class World extends EventTarget {
*
* @see http://bulletphysics.org/mediawiki-1.5.8/index.php/Stepping_The_World
*/
step(dt: number, timeSinceLastCalled = 0, maxSubSteps = 10): void {
if (timeSinceLastCalled === 0) {
step(dt: number, timeSinceLastCalled?: number, maxSubSteps = 10): void {
if (timeSinceLastCalled === undefined) {
// Fixed, simple stepping

this.internalStep(dt)
Expand All @@ -410,7 +410,9 @@ export class World extends EventTarget {
}
}

const t = (this.accumulator % dt) / dt
this.accumulator = this.accumulator % dt

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

0 comments on commit 2970232

Please sign in to comment.