Kinematic-dynamic continuous collision detection
- Dominant language
- Rust
- Stars
- 5.7k
- Forks
- 387
- Avg merge
- 4d 23h
- Merged PRs (30d)
- 6
Description
A kinematic collider does not perform continuous collision detection with a dynamic collider. A small reproducing example is shown below:
```rust
use rapier2d::prelude::*;
use rapier_testbed2d::Testbed;
pub fn init_world(testbed: &mut Testbed) {
/*
* World
*/
let mut bodies = RigidBodySet::new();
let mut colliders = ColliderSet::new();
let impulse_joints = ImpulseJointSet::new();
let multibody_joints = MultibodyJointSet::new();
// "static" dynamic ball
let rigid_body = RigidBodyBuilder::new_dynamic().ccd_enabled(true)
.gravity_scale(0.0).build();
let static_handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::ball(1.0).build();
colliders.insert_with_parent(collider, static_handle, &mut bodies);
// Really fast moving ball
let rigid_body = RigidBodyBuilder::new_kinematic_position_based()
.translation(vector![-5.0, 0.0])
//.linvel(vector![1000.0, 0.0])
.ccd_enabled(true)
.build();
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::ball(1.0).build();
colliders.insert_with_parent(collider, handle, &mut bodies);
// Update kinematic ball so it moves really fast
testbed.add_callback(move |_, physics, _, run_state| {
// Update the position-based kinematic body by setting its next position.
if let Some(ball) = physics.bodies.get_mut(handle) {
let mut next_tra = *ball.translation();
next_tra += vector![1000.0, 0.0];
ball.set_next_kinematic_translation(next_tra);
}
});
/*
* Set up the testbed.
*/
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
testbed.look_at(point![0.0, 2.5], 20.0);
}
```
If `new_kinematic_position_based` is changed to `new_dynamic`, the `linvel` line is uncommented, and the callback is removed, the continuous collision detection works.
On this topic, kinematic-static continuous collision detection doesn't work either (when the appropriate `ActiveCollisionTypes` is set, of course); no contact event gets generated.
Contributor guide
Assessment
This issue has not been assessed yet.