Skip to content

Commit

Permalink
feat: Set a restriction that the value of fixedTimeStep must be great…
Browse files Browse the repository at this point in the history
…er than 0
  • Loading branch information
luzhuang committed Aug 29, 2023
1 parent 772fe2f commit 3b2522f
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions packages/core/src/physics/PhysicsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class PhysicsManager {

private _engine: Engine;
private _restTime: number = 0;
private _fixedTimeStep: number = 1 / 60;

private _colliders: DisorderedArray<Collider> = new DisorderedArray();

Expand Down Expand Up @@ -152,9 +153,6 @@ export class PhysicsManager {
}
};

/** The fixed time step in seconds at which physics are performed. */
fixedTimeStep: number = 1 / 60;

/**
* The gravity of physics scene.
*/
Expand All @@ -169,6 +167,19 @@ export class PhysicsManager {
}
}

/** The fixed time step in seconds at which physics are performed. */
get fixedTimeStep(): number {
return this._fixedTimeStep;
}

set fixedTimeStep(value: number) {
if (value > 0) {
this._fixedTimeStep = value;
} else {
console.warn("fixedTimeStep must be greater than 0.");
}
}

constructor(engine: Engine) {
this._engine = engine;

Expand Down Expand Up @@ -302,7 +313,7 @@ export class PhysicsManager {
* @internal
*/
_update(deltaTime: number): void {
const { fixedTimeStep, _nativePhysicsManager: nativePhysicsManager } = this;
const { _fixedTimeStep: fixedTimeStep, _nativePhysicsManager: nativePhysicsManager } = this;
const componentsManager = this._engine._componentsManager;

const simulateTime = this._restTime + deltaTime;
Expand Down

0 comments on commit 3b2522f

Please sign in to comment.