From 2fec62b5cf8c2e2050394f6e9eebf9b38cf61f7b Mon Sep 17 00:00:00 2001 From: "jiaxin.lai" Date: Sat, 4 Jan 2020 09:30:14 +0800 Subject: [PATCH] fix body enabled after add or remove shapes (#6024) --- cocos/physics/ammo/ammo-shared-body.ts | 4 ++++ cocos/physics/ammo/shapes/ammo-shape.ts | 10 ---------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/cocos/physics/ammo/ammo-shared-body.ts b/cocos/physics/ammo/ammo-shared-body.ts index 6f154ab6ca..8888e1dda7 100644 --- a/cocos/physics/ammo/ammo-shared-body.ts +++ b/cocos/physics/ammo/ammo-shared-body.ts @@ -197,12 +197,14 @@ export class AmmoSharedBody { if (index < 0) { this.ghostStruct.wrappedShapes.push(v); v.setCompound(this.ghostCompoundShape); + this.ghostEnabled = true; } } else { const index = this.bodyStruct.wrappedShapes.indexOf(v); if (index < 0) { this.bodyStruct.wrappedShapes.push(v); v.setCompound(this.bodyCompoundShape); + this.bodyEnabled = true; } } } @@ -213,12 +215,14 @@ export class AmmoSharedBody { if (index >= 0) { this.ghostStruct.wrappedShapes.splice(index, 1); v.setCompound(null); + this.ghostEnabled = false; } } else { const index = this.bodyStruct.wrappedShapes.indexOf(v); if (index >= 0) { this.bodyStruct.wrappedShapes.splice(index, 1); v.setCompound(null); + this.bodyEnabled = false; } } } diff --git a/cocos/physics/ammo/shapes/ammo-shape.ts b/cocos/physics/ammo/shapes/ammo-shape.ts index d1cc815290..97842ad84a 100644 --- a/cocos/physics/ammo/shapes/ammo-shape.ts +++ b/cocos/physics/ammo/shapes/ammo-shape.ts @@ -97,11 +97,6 @@ export class AmmoShape implements IBaseShape { onEnable () { this._isEnabled = true; this._sharedBody.addShape(this, this._isTrigger); - if (this._isTrigger) { - this._sharedBody.ghostEnabled = true; - } else { - this._sharedBody.bodyEnabled = true; - } this.material = this.collider.sharedMaterial!; } @@ -109,11 +104,6 @@ export class AmmoShape implements IBaseShape { onDisable () { this._isEnabled = false; this._sharedBody.removeShape(this, this._isTrigger); - if (this._isTrigger) { - this._sharedBody.ghostEnabled = false; - } else { - this._sharedBody.bodyEnabled = false; - } } onDestroy () {