Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/CannonPysiceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -387,6 +388,7 @@ export class CannonPysiceManager implements IPhysicsManager {
CannonCollider._addUpdateList = true;
this._updateCollisions();
this.dispatchCollideEvent();
this._updateCount++;
}

/**
Expand Down
10 changes: 6 additions & 4 deletions src/Collider/CannonRigidBodyCollider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
}
}
Expand Down