diff --git a/src/CannonPysiceManager.ts b/src/CannonPysiceManager.ts index 313f02f..dc6d13b 100644 --- a/src/CannonPysiceManager.ts +++ b/src/CannonPysiceManager.ts @@ -244,8 +244,8 @@ export class CannonPysiceManager implements IPhysicsManager { let loopCount = this._updateCount; for (var i: number = 0, n: number = this._currentFrameCollisions.length; i < n; i++) { var curFrameCol: Collision = this._currentFrameCollisions[i]; - var colliderA: CannonCollider = curFrameCol._colliderA as CannonCollider; - var colliderB: CannonCollider = curFrameCol._colliderB as CannonCollider; + var colliderA = curFrameCol._colliderA.component; + var colliderB = curFrameCol._colliderB.component; if (colliderA._destroyed || colliderB._destroyed)//前一个循环可能会销毁后面循环的同一物理组件 continue; let ownerA = colliderA.owner; @@ -275,8 +275,8 @@ export class CannonPysiceManager implements IPhysicsManager { for (i = 0, n = this._previousFrameCollisions.length; i < n; i++) { var preFrameCol = this._previousFrameCollisions[i]; - var preColliderA = preFrameCol._colliderA as CannonCollider; - var preColliderB = preFrameCol._colliderB as CannonCollider; + var preColliderA = preFrameCol._colliderA.component; + var preColliderB = preFrameCol._colliderB.component; if (preColliderA._destroyed || preColliderB._destroyed) continue; let ownerA = preColliderA.owner; @@ -334,6 +334,7 @@ export class CannonPysiceManager implements IPhysicsManager { if (!collider._isSimulate) { return; } + collider.inPhysicUpdateListIndex != undefined && (collider.inPhysicUpdateListIndex = -1); this._discreteDynamicsWorld.removeBody(collider._cannonColliderObject); collider._isSimulate = false; } @@ -387,6 +388,7 @@ export class CannonPysiceManager implements IPhysicsManager { CannonCollider._addUpdateList = true; this._updateCollisions(); this.dispatchCollideEvent(); + this._updateCount++; } /** diff --git a/src/Collider/CannonRigidBodyCollider.ts b/src/Collider/CannonRigidBodyCollider.ts index e8f5ad3..4a7928b 100644 --- a/src/Collider/CannonRigidBodyCollider.ts +++ b/src/Collider/CannonRigidBodyCollider.ts @@ -154,11 +154,13 @@ export class CannonRigidBodyCollider extends CannonCollider implements IDynamicC natColObj.type = CANNON.Body.KINEMATIC; this._enableProcessCollisions = false; this._updateMass(0);//必须设置Mass为0来保证InverMass为0 + this.inPhysicUpdateListIndex = -1; } else { natColObj.allowSleep = true; natColObj.type = CANNON.Body.DYNAMIC; this._enableProcessCollisions = true; this._updateMass(this._mass); + this.inPhysicUpdateListIndex = undefined; } natColObj.velocity.set(0.0, 0.0, 0.0); natColObj.angularVelocity.set(0.0, 0.0, 0.0); @@ -244,13 +246,13 @@ export class CannonRigidBodyCollider extends CannonCollider implements IDynamicC var flag = this._cannonColliderObject.type; //TODO:可能要改 this._cannonColliderObject.collisionResponse = false; - if ((flag & CANNON.Body.STATIC) === 0) - this._cannonColliderObject.type |= CANNON.Body.STATIC; + // if ((flag & CANNON.Body.STATIC) === 0) + // this._cannonColliderObject.type |= CANNON.Body.STATIC; } else { //TODO:可能要改 this._cannonColliderObject.collisionResponse = true; - if ((flag & CANNON.Body.STATIC) !== 0) - this._cannonColliderObject.type ^= CANNON.Body.STATIC; + // if ((flag & CANNON.Body.STATIC) !== 0) + // this._cannonColliderObject.type ^= CANNON.Body.STATIC; } } }