Skip to content
Merged
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
1 change: 1 addition & 0 deletions dist/preview release/what's new.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@

- Fixed time steps or delta time with sub time step for Oimo.js and Cannon.js ([cedricguillemet](https://github.com/cedricguillemet))
- Ammo.js collision group and mask supported by impostor parameters ([cedricguillemet](https://github.com/cedricguillemet))
- `collisionResponse` flag to disable response but still get onCollide events ([cedricguillemet](https://github.com/cedricguillemet))
- Ammo.js IDL exposed property update and raycast vehicle stablization support ([MackeyK24](https://github.com/MackeyK24))
- Recast.js plugin nav mesh and crowd agent to ref performance optimizations. ([MackeyK24](https://github.com/MackeyK24))
- Added `scene.physicsEnabled` boolean ([Deltakosh](https://github.com/deltakosh))
Expand Down
17 changes: 11 additions & 6 deletions src/Collisions/collider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,13 +368,18 @@ export class Collider {
var distToCollision = t * this._velocity.length();

if (!this.collisionFound || distToCollision < this._nearestDistance) {
if (!this.intersectionPoint) {
this.intersectionPoint = this._collisionPoint.clone();
} else {
this.intersectionPoint.copyFrom(this._collisionPoint);
// if collisionResponse is false, collision is not found but the collidedMesh is set anyway.
// onCollide observable are triggered if collideMesh is set
// this allow trigger volumes to be created.
if (hostMesh.collisionResponse) {
if (!this.intersectionPoint) {
this.intersectionPoint = this._collisionPoint.clone();
} else {
this.intersectionPoint.copyFrom(this._collisionPoint);
}
this._nearestDistance = distToCollision;
this.collisionFound = true;
}
this._nearestDistance = distToCollision;
this.collisionFound = true;
this.collidedMesh = hostMesh;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/Collisions/meshCollisionData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ export class _MeshCollisionData {
public _diffPositionForCollisions = new Vector3(0, 0, 0);
public _onCollideObserver: Nullable<Observer<AbstractMesh>>;
public _onCollisionPositionChangeObserver: Nullable<Observer<Vector3>>;
public _collisionResponse = true;
}
13 changes: 13 additions & 0 deletions src/Meshes/abstractMesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,19 @@ export class AbstractMesh extends TransformNode implements IDisposable, ICullabl
this._meshCollisionData._collisionMask = !isNaN(mask) ? mask : -1;
}

/**
* Gets or sets a collision response flag (default is true).
* when collisionResponse is false, events are still triggered but colliding entity has no response
* This helps creating trigger volume when user wants collision feedback events but not position/velocity
* to respond to the collision.
*/
public get collisionResponse(): boolean {
return this._meshCollisionData._collisionResponse;
}

public set collisionResponse(response: boolean) {
this._meshCollisionData._collisionResponse = response;
}
/**
* Gets or sets the current collision group mask (-1 by default).
* A collision between A and B will happen if A.collisionGroup & b.collisionMask !== 0
Expand Down