From 8bb8eb8935eee227bb15029a2efa1533251140a5 Mon Sep 17 00:00:00 2001 From: "jiaxin.lai" Date: Mon, 9 Dec 2019 18:28:53 +0800 Subject: [PATCH] add useFixedTime to physics system (#5871) --- cocos/physics/components/physics-system.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/cocos/physics/components/physics-system.ts b/cocos/physics/components/physics-system.ts index 83d59a623b..5986f2bc24 100644 --- a/cocos/physics/components/physics-system.ts +++ b/cocos/physics/components/physics-system.ts @@ -80,6 +80,18 @@ export class PhysicsSystem extends System { this._deltaTime = value; } + /** + * @zh + * 获取或设置是否使用固定的时间步长进行模拟,默认为 true。 + */ + get useFixedTime () { + return this._useFixedTime; + } + + set useFixedTime (value: boolean) { + this._useFixedTime = value; + } + /** * @zh * 获取或设置物理世界的重力数值,默认为 (0, -10, 0) @@ -135,6 +147,7 @@ export class PhysicsSystem extends System { private _enable = true; private _deltaTime = 1.0 / 60.0; + private _useFixedTime = true; private _maxSubStep = 2; // private _frameRate = 60; // private _singleStep = false; @@ -185,7 +198,11 @@ export class PhysicsSystem extends System { director.emit(Director.EVENT_BEFORE_PHYSICS); - this._world.step(this._deltaTime, deltaTime, this._maxSubStep); + if (this._useFixedTime) { + this._world.step(this._deltaTime); + } else { + this._world.step(this._deltaTime, deltaTime, this._maxSubStep); + } // if (this._singleStep) { // this._enable = false; // }