Skip to content

Conversation

@Deniskore
Copy link

PR is only partially based on the PR from lukasfri.

This PR implements the following changes:

  1. Updated Bevy to version 0.17.2 and all other dependencies to their latest versions.
  2. I believe Jondolf's comment is more logically correct, so I didn't change CollisionEvent to CollisionMessage.
  3. Manually tested several examples. Note that the [dev-dependencies] some of the 2D examples require extended features otherwise, you'll get a white screen with nothing displayed.
  4. Updated voxel shape views according to the latest changes in the parry2d library.
  5. Investigated the issue related to ColliderDisabled and found a regression in rapier, introduced in this PR, also the issue was mentioned in js bindings setEnabled to false on collider do not disable collision in 0.18.x. rapier.js#344
  6. All dependencies are now up to date, so the wasm_js flag is no longer needed. The latest version of getrandom fixes this, and I’ve verified it works locally.
  7. Added the voxels2_no_collider example, to demonstrate that it's not working correctly at the moment. I can remove it if it's not needed.

Steps to reproduce the issue ColliderDisabled in rapier repo:

  1. Clone rapier repo and reset rapier to commit efa7e764ba2bb1313697431c2a5829e611dd7d23 (v0.27.0)
  2. Replace the voxels code with the patch below (only executed set_enabled(false) and added mass 1.0 for spawned bodies)
  3. Run cargo run -p rapier-examples-2d --release and choose the voxels example
  4. All spawned bodies will fall through the floor
  5. Reset rapier to commit 317322b31b1ecf3732676dbb90fcfd5f90c8d0de (v0.28.0)
  6. Run cargo run -p rapier-examples-2d --release and choose the voxels example. All spawned bodies will collide with the floor and will not go through it. Reproducible on v0.30.1 too.
diff --git a/examples2d/voxels2.rs b/examples2d/voxels2.rs
index 7feeaa2..0afa5d2 100644
--- a/examples2d/voxels2.rs
+++ b/examples2d/voxels2.rs
@@ -39,10 +39,12 @@ pub fn init_world(testbed: &mut Testbed) {
     let nx = 50;
     for i in 0..nx {
         for j in 0..10 {
-            let mut rb = RigidBodyBuilder::dynamic().translation(vector![
-                i as f32 * 2.0 - nx as f32 / 2.0,
-                20.0 + j as f32 * 2.0
-            ]);
+            let mut rb = RigidBodyBuilder::dynamic()
+                .translation(vector![
+                    i as f32 * 2.0 - nx as f32 / 2.0,
+                    20.0 + j as f32 * 2.0
+                ])
+                .additional_mass(1.0);
             if test_ccd {
                 rb = rb.linvel(vector![0.0, -1000.0]).ccd_enabled(true);
             }
@@ -61,7 +63,10 @@ pub fn init_world(testbed: &mut Testbed) {
                 2 => ColliderBuilder::capsule_y(ball_radius, ball_radius),
                 _ => unreachable!(),
             };
-            colliders.insert_with_parent(co, rb_handle, &mut bodies);
+            let co_handle = colliders.insert_with_parent(co, rb_handle, &mut bodies);
+            if let Some(co_mut) = colliders.get_mut(co_handle) {
+                co_mut.set_enabled(false);
+            }
         }
     }
 
@@ -84,7 +89,12 @@ pub fn init_world(testbed: &mut Testbed) {
     let rb = bodies.insert(RigidBodyBuilder::fixed().translation(vector![-20.0, -10.0]));
     let shape = SharedShape::voxelized_mesh(&polyline, &indices, 0.2, FillMode::default());
 
-    colliders.insert_with_parent(ColliderBuilder::new(shape), rb, &mut bodies);
+    // Insert the voxelized mesh collider and disable it (non-collidable) per user request.
+    let voxel_mesh_handle =
+        colliders.insert_with_parent(ColliderBuilder::new(shape), rb, &mut bodies);
+    if let Some(co_mut) = colliders.get_mut(voxel_mesh_handle) {
+        co_mut.set_enabled(false);
+    }
 
     /*
      * A voxel wavy floor.

@Deniskore
Copy link
Author

I fixed ColliderDisabled issue in Rapier locally and all tests pass, though I'm not sure it's the perfect solution. I'll open a PR and follow up with the maintainers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants