Skip to content

Commit

Permalink
Actually so much better
Browse files Browse the repository at this point in the history
  • Loading branch information
HunterBarclay committed Jun 28, 2024
1 parent 1f843d7 commit bc8680f
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions fission/src/systems/physics/PhysicsSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}`)

Expand Down

0 comments on commit bc8680f

Please sign in to comment.