Sfoglia il codice sorgente

Fixed time steps or delta time with sub time step for Oimo.js and Cannon.js

Cedric Guillemet 5 anni fa
parent
commit
6e49fc00f5

+ 1 - 0
dist/preview release/what's new.md

@@ -43,6 +43,7 @@
 
 
 ### Physics
 ### Physics
 
 
+- Fixed time steps or delta time with sub time step for Oimo.js and Cannon.js ([cedricguillemet](https://github.com/cedricguillemet))
 - Ammo.js IDL exposed property update and raycast vehicle stablization support ([MackeyK24](https://github.com/MackeyK24))
 - Ammo.js IDL exposed property update and raycast vehicle stablization support ([MackeyK24](https://github.com/MackeyK24))
 - Recast.js plugin nav mesh and crowd agent to ref performance optimizations. ([MackeyK24](https://github.com/MackeyK24))
 - Recast.js plugin nav mesh and crowd agent to ref performance optimizations. ([MackeyK24](https://github.com/MackeyK24))
 
 

+ 1 - 1
src/Physics/Plugins/cannonJSPlugin.ts

@@ -54,7 +54,7 @@ export class CannonJSPlugin implements IPhysicsEnginePlugin {
     }
     }
 
 
     public executeStep(delta: number): void {
     public executeStep(delta: number): void {
-        this.world.step(this._fixedTimeStep, this._useDeltaForWorldStep ? delta : 0, 3);
+        this.world.step(this._useDeltaForWorldStep ? delta : this._fixedTimeStep);
         this._removeMarkedPhysicsBodiesFromWorld();
         this._removeMarkedPhysicsBodiesFromWorld();
     }
     }
 
 

+ 3 - 1
src/Physics/Plugins/oimoJSPlugin.ts

@@ -17,8 +17,9 @@ export class OimoJSPlugin implements IPhysicsEnginePlugin {
     public name: string = "OimoJSPlugin";
     public name: string = "OimoJSPlugin";
     public BJSOIMO: any;
     public BJSOIMO: any;
     private _raycastResult: PhysicsRaycastResult;
     private _raycastResult: PhysicsRaycastResult;
+    private _fixedTimeStep: number = 1 / 60;
 
 
-    constructor(iterations?: number, oimoInjection = OIMO) {
+    constructor(private _useDeltaForWorldStep: boolean = true, iterations?: number, oimoInjection = OIMO) {
         this.BJSOIMO = oimoInjection;
         this.BJSOIMO = oimoInjection;
         this.world = new this.BJSOIMO.World({
         this.world = new this.BJSOIMO.World({
             iterations: iterations
             iterations: iterations
@@ -47,6 +48,7 @@ export class OimoJSPlugin implements IPhysicsEnginePlugin {
             impostor.beforeStep();
             impostor.beforeStep();
         });
         });
 
 
+        this.world.timeStep = this._useDeltaForWorldStep ? delta : this._fixedTimeStep;
         this.world.step();
         this.world.step();
 
 
         impostors.forEach((impostor) => {
         impostors.forEach((impostor) => {