diff --git a/cocos/physics-2d/box2d-wasm/joints/fixed-joint.ts b/cocos/physics-2d/box2d-wasm/joints/fixed-joint.ts index 6084d7e55c5..32ea72a8a65 100644 --- a/cocos/physics-2d/box2d-wasm/joints/fixed-joint.ts +++ b/cocos/physics-2d/box2d-wasm/joints/fixed-joint.ts @@ -30,10 +30,14 @@ import { PHYSICS_2D_PTM_RATIO } from '../../framework/physics-types'; export class B2FixedJoint extends B2Joint implements IFixedJoint { setFrequency (v: number): void { - (this._b2joint as B2.WeldJoint).SetFrequency(v); + if (this._b2joint) { + (this._b2joint as B2.WeldJoint).SetFrequency(v); + } } setDampingRatio (v: number): void { - (this._b2joint as B2.WeldJoint).SetDampingRatio(v); + if (this._b2joint) { + (this._b2joint as B2.WeldJoint).SetDampingRatio(v); + } } _createJointDef (): any { diff --git a/cocos/physics-2d/box2d-wasm/joints/spring-joint.ts b/cocos/physics-2d/box2d-wasm/joints/spring-joint.ts index e0ca9102b88..81e9451c6bf 100644 --- a/cocos/physics-2d/box2d-wasm/joints/spring-joint.ts +++ b/cocos/physics-2d/box2d-wasm/joints/spring-joint.ts @@ -30,12 +30,15 @@ import { PHYSICS_2D_PTM_RATIO } from '../../framework/physics-types'; export class B2SpringJoint extends B2Joint implements ISpringJoint { setFrequency (v: number): void { - (this._b2joint as B2.DistanceJoint).SetFrequency(v); + if (this._b2joint) { + (this._b2joint as B2.DistanceJoint).SetFrequency(v); + } } setDampingRatio (v: number): void { - //this.updateStiffnessAndDamping(); - (this._b2joint as B2.DistanceJoint).SetDampingRatio(v); + if (this._b2joint) { + (this._b2joint as B2.DistanceJoint).SetDampingRatio(v); + } } setDistance (v: number): void { diff --git a/cocos/physics-2d/box2d-wasm/joints/wheel-joint.ts b/cocos/physics-2d/box2d-wasm/joints/wheel-joint.ts index c2faa6e1654..9f8625ae944 100644 --- a/cocos/physics-2d/box2d-wasm/joints/wheel-joint.ts +++ b/cocos/physics-2d/box2d-wasm/joints/wheel-joint.ts @@ -31,10 +31,14 @@ import { toRadian } from '../../../core'; export class B2WheelJoint extends B2Joint implements IWheelJoint { setFrequency (v: number): void { - (this._b2joint as B2.WheelJoint as any).SetSpringFrequencyHz(v); + if (this._b2joint) { + (this._b2joint as B2.WheelJoint as any).SetSpringFrequencyHz(v); + } } setDampingRatio (v: number): void { - (this._b2joint as B2.WheelJoint as any).SetSpringDampingRatio(v); + if (this._b2joint) { + (this._b2joint as B2.WheelJoint as any).SetSpringDampingRatio(v); + } } // motor