pub fn contact(
collider1: &Collider,
position1: RVector,
rotation1: impl Into<Quat>,
collider2: &Collider,
position2: RVector,
rotation2: impl Into<Quat>,
prediction_distance: f32,
) -> Result<Option<SingleContact>, UnsupportedShape>Expand description
Computes one pair of contact points between two Colliders.
Returns None if the colliders are separated by a distance greater than prediction_distance
or if the given shapes are invalid.
ยงExample
use avian3d::{collision::collider::contact_query::contact, math::RVec3, prelude::*};
use bevy::prelude::*;
let collider1 = Collider::sphere(0.5);
let collider2 = Collider::cuboid(1.0, 1.0, 1.0);
// Compute a contact that should have a penetration depth of 0.5
let contact = contact(
// First collider
&collider1,
RVec3::default(),
Quat::default(),
// Second collider
&collider2,
RVec3::X * 0.5,
Quat::default(),
// Prediction distance
0.0,
)
.expect("Unsupported collider shape");
assert_eq!(
contact.is_some_and(|contact| contact.penetration == 0.5),
true
);