Hey guys… im trying to figure out if i can make some sort of Trigger Volume feature using the mesh.onCollideObservable.
I need to create a box with mesh check collisions enable so i can get the mesh.onCollide obserable event and hand my collision detection with the other mesh… works perfect but cant pass thru the other mesh (which is what its support to do). I need to pass thru object and still get collide event … Like a trigger volume from unity or unreal.
in Ammo.js i would set a collision flag (CF_NO_CONTACT_RESPONSE) to allow passing thru but still get collision events
if (trigger === true) body.setCollisionFlags(body.getCollisionFlags() | BABYLON.CollisionFlags.CF_NO_CONTACT_RESPONSE | BABYLON.CollisionFlags.CF_CUSTOM_MATERIAL_CALLBACK);
else body.setCollisionFlags(body.getCollisionFlags() | BABYLON.CollisionFlags.CF_CUSTOM_MATERIAL_CALLBACK);
Anybody got any ideas i can handle something like this with the Check Collision System
???
sebavan
September 8, 2020, 12:21pm
2
Adding @RaananW and @Cedric in case they have an idea
Cedric
September 8, 2020, 12:34pm
3
There are collisionGroup and collisionMask but this will disable collision,
* @see https://doc.babylonjs.com/babylon101/cameras,_mesh_collisions_and_gravity
*/
public ellipsoid = new Vector3(0.5, 1, 0.5);
/**
* Gets or sets the ellipsoid offset used to impersonate this mesh when using collision engine (default is (0, 0, 0))
* @see https://doc.babylonjs.com/babylon101/cameras,_mesh_collisions_and_gravity
*/
public ellipsoidOffset = new Vector3(0, 0, 0);
/**
* Gets or sets a collision mask used to mask collisions (default is -1).
* A collision between A and B will happen if A.collisionGroup & b.collisionMask !== 0
*/
public get collisionMask(): number {
return this._meshCollisionData._collisionMask;
}
public set collisionMask(mask: number) {
this._meshCollisionData._collisionMask = !isNaN(mask) ? mask : -1;
}
To disable collision response, AFAIK, a new flag and test is needed here to move the move whether there is a collision or not:
// if not specified, against all meshes in the scene
var meshes = (excludedMesh && excludedMesh.surroundingMeshes) || this._scene.meshes;
for (var index = 0; index < meshes.length; index++) {
var mesh = meshes[index];
if (mesh.isEnabled() && mesh.checkCollisions && mesh.subMeshes && mesh !== excludedMesh && ((collisionMask & mesh.collisionGroup) !== 0)) {
mesh._checkCollision(collider);
}
}
if (!collider.collisionFound) {
position.addToRef(velocity, finalPosition);
return;
}
if (velocity.x !== 0 || velocity.y !== 0 || velocity.z !== 0) {
collider._getResponse(position, velocity);
}
if (velocity.length() <= closeDistance) {
finalPosition.copyFrom(position);
So what do you say @Deltakosh … Can we get this in there… Pretty please
So @Cedric … Where should put the collisionResponse flag ???
Do you wanna go ahead and make the PR ???
That would be awesome
1 Like
Cedric
September 9, 2020, 1:22pm
8
PR is live, let me know if I got you wrong with this flag
BabylonJS:master
← CedricGuillemet:collisionContactResponse
opened 01:21PM - 09 Sep 20 UTC
2 Likes
Yo @Cedric … thanks for making the PR… Going to try it out tonight
1 Like
Hello, thanks for this update, exactly what I needed!
Would it also possible to detect when a collision leaves?
for example detecting when entering and leaving a trigger mesh
Previously I was checking for if intersectsMesh is false, but needed more accurate detecting than a bounding box
EDIT:
Will try a custom check with Check When a Point is Inside a Mesh | Babylon.js Documentation and see how it goes
1 Like