dimforge / rapier

2D and 3D physics engines focused on performance.
https://rapier.rs
Apache License 2.0
3.8k stars 236 forks source link

collider `solver_groups` not behaving as expected #512

Closed bcolloran closed 3 months ago

bcolloran commented 11 months ago

The docs on collision and solver groups say:

"solver_groups is here to prevent contact forces from being computed between some colliders, whereas the collision_groups will also prevent the contact themselves (and contact events) from being computed"

Based on the docs, I would expect that if I successfully create a set of InteractionGroups that disable collisions altogether using collision_groups(...), that I should be able to disable the physics calculations without disabling the collision detection by replacing collision_groups(...) with solver_groups(...). However, this does not work, as you can see if you attempt it in this example:

https://github.com/dimforge/rapier/blob/master/examples2d/collision_groups2.rs

Namely, if you replace line 75 of that file:

let collider = ColliderBuilder::cuboid(rad, rad).collision_groups(group);

with this:

let collider = ColliderBuilder::cuboid(rad, rad).solver_groups(group);

In the unmodified example, the green and blue objects are in different collision_groups, so they simply never collide, and the green boxes fall through the blue platform.

Likewise, when you make the modification described above, since the green and blue objects are in different solver_groups, I expect that they should not compute and apply forces between the green and blue objects, and that the green boxes should once again fall through the blue platform. However, this is not the case: the green boxes come to rest on top of the blue platform, so it's clear that the solver_group is not disabling the computation of forces between these groups.

sebcrozet commented 3 months ago

By changing only the line 75, you are changing the solver group of the dynamic bodies, but the floor still have the default solver group (which is compatible with every other group). So you will loose force computation between the green and blue dynamic bodies, but not between the dynamic bodies in the floor.

To achieve the desired effect you would have to change collision_groups to solver_groups on both the static and dynamic objects.

Please reopen if you still have issues with the suggested solution.