From 1b53eb912e46df8e1335f3c15a6d7bcfdba1f872 Mon Sep 17 00:00:00 2001 From: polygonboutique Date: Fri, 7 Oct 2016 10:21:50 +0200 Subject: [PATCH] update --- game-lib.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/game-lib.js b/game-lib.js index 8dfbb75..efd598a 100644 --- a/game-lib.js +++ b/game-lib.js @@ -1172,6 +1172,7 @@ GameLib.D3.Physics.World = function( this.worldObject = new CANNON.World(); this.worldObject.gravity.set(this.gravity.x, this.gravity.y, this.gravity.z); this.worldObject.broadphase = new CANNON.NaiveBroadphase(); + //this.worldObject.broadphase = new CANNON.SAPBroadphase(); this.worldObject.solver.iterations = 10; } }; @@ -2825,7 +2826,21 @@ GameLib.D3.Physics.World.prototype.Step = function( timeStep ) { if(this.engineType == GameLib.D3.Physics.Engine.TYPE_CANNON) { - this.worldObject.step(timeStep); + + var now = performance.now() / 1000; + + if(!this.lastCallTime){ + // last call time not saved, cant guess elapsed time. Take a simple step. + this.worldObject.step(timeStep); + this.lastCallTime = now; + return; + } + + var timeSinceLastCall = now - this.lastCallTime; + + this.worldObject.step(timeStep, timeSinceLastCall); + + this.lastCallTime = now; } };