Skip to content

Commit 0c8f94f

Browse files
authored
Fix shape contact when velocity is 0 (#328)
- Fixes #307
1 parent db3a546 commit 0c8f94f

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/rapier_wrapper/query.rs

+32
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,38 @@ impl PhysicsEngine {
246246
compute_impact_geometry_on_penetration: true,
247247
..Default::default()
248248
};
249+
// Stationary shapes
250+
if shape_vel1.magnitude_squared() < DEFAULT_EPSILON
251+
&& shape_vel2.magnitude_squared() < DEFAULT_EPSILON
252+
{
253+
let contact_result = parry::query::contact(
254+
&shape_transform1,
255+
shared_shape1.as_ref(),
256+
&shape_transform2,
257+
shared_shape2.as_ref(),
258+
0.0,
259+
);
260+
match contact_result {
261+
Ok(None) => {}
262+
Ok(Some(contact)) => {
263+
// the distance is negative if there is intersection
264+
if contact.dist <= 0.0 {
265+
result.toi = 0.0;
266+
result.collided = true;
267+
result.normal1 = contact.normal1.into_inner();
268+
result.normal2 = contact.normal2.into_inner();
269+
result.pixel_witness1 = contact.point1.coords
270+
+ shape_info1.transform.translation.vector;
271+
result.pixel_witness2 = contact.point2.coords
272+
+ shape_info2.transform.translation.vector;
273+
}
274+
}
275+
Err(err) => {
276+
godot_error!("contact error: {:?}", err);
277+
}
278+
}
279+
return result;
280+
}
249281
let toi_result = parry::query::cast_shapes(
250282
&shape_transform1,
251283
&shape_vel1,

0 commit comments

Comments
 (0)