Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f1c80c2

Browse files
committedJun 26, 2020
Limit the accumulator and allow dt of 0, from schteppe#392
1 parent f47229a commit f1c80c2

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed
 

‎src/world/World.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,8 @@ export class World extends EventTarget {
385385
*
386386
* @see http://bulletphysics.org/mediawiki-1.5.8/index.php/Stepping_The_World
387387
*/
388-
step(dt: number, timeSinceLastCalled = 0, maxSubSteps = 10): void {
389-
if (timeSinceLastCalled === 0) {
388+
step(dt: number, timeSinceLastCalled?: number, maxSubSteps = 10): void {
389+
if (timeSinceLastCalled === undefined) {
390390
// Fixed, simple stepping
391391

392392
this.internalStep(dt)
@@ -410,7 +410,9 @@ export class World extends EventTarget {
410410
}
411411
}
412412

413-
const t = (this.accumulator % dt) / dt
413+
this.accumulator = this.accumulator % dt
414+
415+
const t = this.accumulator / dt
414416
for (let j = 0; j !== this.bodies.length; j++) {
415417
const b = this.bodies[j]
416418
b.previousPosition.lerp(b.position, t, b.interpolatedPosition)

0 commit comments

Comments
 (0)
Please sign in to comment.