diff --git a/fission/src/systems/physics/PhysicsSystem.ts b/fission/src/systems/physics/PhysicsSystem.ts index 6cfedd4d74..dd87a1c79d 100644 --- a/fission/src/systems/physics/PhysicsSystem.ts +++ b/fission/src/systems/physics/PhysicsSystem.ts @@ -34,7 +34,9 @@ const COUNT_OBJECT_LAYERS = 11 export const STANDARD_SIMULATION_PERIOD = 1.0 / 60.0 const MIN_SIMULATION_PERIOD = 1.0 / 120.0 const MAX_SIMULATION_PERIOD = 1.0 / 10.0 -const STANDARD_SUB_STEPS = 2 +const MIN_SUBSTEPS = 2 +const MAX_SUBSTEPS = 6 +const STANDARD_SUB_STEPS = 4 const TIMESTEP_ADJUSTMENT = 0.0001 let lastDeltaT = STANDARD_SIMULATION_PERIOD @@ -714,11 +716,12 @@ class PhysicsSystem extends WorldSystem { public Update(deltaT: number): void { const diffDeltaT = deltaT - lastDeltaT - lastDeltaT = lastDeltaT + Math.min(TIMESTEP_ADJUSTMENT, Math.max(-TIMESTEP_ADJUSTMENT, diffDeltaT)) + lastDeltaT = lastDeltaT + Math.min(TIMESTEP_ADJUSTMENT, Math.max(-TIMESTEP_ADJUSTMENT, diffDeltaT)) lastDeltaT = Math.min(MAX_SIMULATION_PERIOD, Math.max(MIN_SIMULATION_PERIOD, lastDeltaT)) - const substeps = Math.max(1, Math.floor((STANDARD_SIMULATION_PERIOD / lastDeltaT) * STANDARD_SUB_STEPS)) + let substeps = Math.max(1, Math.floor((lastDeltaT / STANDARD_SIMULATION_PERIOD) * STANDARD_SUB_STEPS)) + substeps = Math.min(MAX_SUBSTEPS, Math.max(MIN_SUBSTEPS, substeps)) console.log(`DeltaT: ${lastDeltaT.toFixed(5)}, Substeps: ${substeps}`)