Collision between mesh objects not working with constraint movement

Hi,
Collision does not seem to be working between two Mesh collision objects, when moved by an attached Point2Point constraint.

I am dragging objects by attaching a constraint with a temporary sphere using grab/drag.
The grab-ball is moved with teleport along a horizontal plane determined by the grab point.

This all works fine for grabbing/moving objects with Box-Collisions. The boxes cannot pass through the other box or through the other meshes.

For the Mesh objects, it works only when interacting with Boxes, but not with the other Mesh object. When dragging the Mesh object, it cannot pass through the Box’s but it can freely pass through the Mesh object.

Hi @openright and welcome,

Mesh to mesh collisions aren’t supported by PlayCanvas.

There is a way to manually enable support for that, check this older post for more on this: Is there any way to make mesh-to-mesh collision?

Thank you for the quick reply. I did see that post about lacking support for “mesh to mesh” right after posting the question. I was going to withdraw my question, but you were too fast for me.

1 Like

Hi @Leonidas, thanks again for your help.

As an alternative to mesh-mesh collisions, I am trying to temporarily change the mesh collision to box collision (for active/moving entity).

Either by manipulating the entity.collision or by replacing collision.

Neither approach is quite working (see below), and I wonder if there is a better way to add/change collision on an existing entity. I thought that perhaps I could also do addChild and at new child of the entity with additional collision. but that did not seem to work either. I have not yet found any examples of adding/changing existing collision type dynamically. Any pointers would be helpful.

For manipulating collision, I can change to ‘box’, but changing back to mesh seems to invalidate the collision.

to box collision:
entity.collision.type = ‘box’;
entity.collision.halfExtents = aabb.halfExtents;

back to mesh:
entity.collision.type = ‘mesh’;

for replacing collision, I seemed to need to disable and reenable rigidbody to avoid error, and there seemed to be some resource leak, as it got slower with a few iterations:

to box collision:
entity.rigidbody.enabled = false;
entity.removeComponent(‘collision’);
entity.addComponent(‘collision’, {halfExtents: aabb.halfExtents});
entity.rigidbody.enabled = true;

back to mesh collision:
entity.rigidbody.enabled = false;
entity.removeComponent(‘collision’);
entity.addComponent(‘collision’, { type: ‘mesh’, renderAsset: entity.render.asset} );
entity.rigidbody.enabled = true;

The engine doesn’t support dynamic mesh colliders. Internally it uses btBvhTriangleMeshShape, which is super efficient to calculate collisions, but it has own limits - it was designed for use as a static mesh only, and some thin dynamic objects can tunnel through it, depending on triangle densities of those bodies.

If you want a non-primitive shape to be dynamic, you should create btConvexHullShape yourself. I don’t think there is an example around, but you can start from studying how the engine creates btBvhTriangleMeshShape. The principal is similar, except an additional step, where you need to call the hull generator.

Another option is to use a compound collider, that has primitive shapes losely matching your mesh shape.