CannonJS not respecting children physicsImpostors when colliding with other physicsImpostors

Hi all! Is it possible to have CannonJS respect children physicsImpostors when colliding with other physicsImpostors?

I’m trying to have a Capsule collider with the bottom sphere as the parent. The cylinder and upper sphere are children of this bottom sphere.

Please find the Playground linked here: https://www.babylonjs-playground.com/#3EDS3A#77

Please click inside the Playground’s scene to activate pointer lock
Controls:
WASD: Move
SPACE: Jump

I wonder if this is impossible physics, since we want the cylinder and upper sphere of the Capsule to neglect collisions between the 3 Capsule physicsImpostors. However, we also want the cylinder and upper sphere to respect collisions with the red slide physicsImpostor.

I would be grateful if anyone could offer insight on this. Thank you :smiley:

Adding @RaananW a cannon master :wink:

1 Like

When applying impostors on a compound (parented objects) you first need to set the children’s impostors and only then the parent:

https://www.babylonjs-playground.com/#3EDS3A#79

Cannon also has a Point-to-point joint type, which practically connects impostors at a fixed point, so it is also an option if you find it hard working with compounds

3 Likes

Thank you so much, @RaananW and @sebavan! This is so amazing! :smiley:

@RaananW, with your solution, the Capsule’s upper portion collision is far better. However, there is still a little bit of clipping, and part of the top sphere and cylinder can enter into the red slide.

I tried using Compounds with Playground example, however Compounds don’t seem to be as precise as dealing with a single mesh and its physicsImpostor.

Could you please view the Playgrounds below?

Playground 1: Single sphere mesh - precise collisions :smiley:

https://www.babylonjs-playground.com/#3EDS3A#92

Playground 2: Compound with single sphere as child - impostors can enter each other :cry:

https://www.babylonjs-playground.com/#3EDS3A#91

If we can somehow make the Compound have precise collisions, then I think we could add the rest of the Capsule (cylinder and sphere) and have precise Capsule collisions. Thank you for all your time and help, @RaananW :smile:

For your reference, here is an attempt to use a Compound for the Capsule, but the Capsule can easily clip into the slide :frowning: : https://www.babylonjs-playground.com/#3EDS3A#88

Ah, turns out where we place the Compound point (center of mass?) has an effect.

Changes made:
Placed Compound point in the center of Capsule (between both spheres and in the center of cylinder)
setAngularVelocity of Compound to zero in every simulation step (seems to not have an effect after the first change was made)

Not perfect yet, but getting very close :stuck_out_tongue: : https://www.babylonjs-playground.com/#3EDS3A#96

The spheres can still slightly clip into the red slide. I think this is because while the Compound point (center of mass) is now in the center of the Capsule, it is not in the center of each sphere?