Function avian3d::collision::contact_query::contact
source · pub fn contact(
collider1: &Collider,
position1: impl Into<Position>,
rotation1: impl Into<Rotation>,
collider2: &Collider,
position2: impl Into<Position>,
rotation2: impl Into<Rotation>,
prediction_distance: Scalar
) -> Result<Option<SingleContact>, UnsupportedShape>
Expand description
Computes one pair of contact points between two Collider
s.
Returns None
if the colliders are separated by a distance greater than prediction_distance
or if the given shapes are invalid.
§Example
use avian3d::prelude::{contact_query::contact, *};
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,
Vec3::default(),
Quat::default(),
// Second collider
&collider2,
Vec3::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
);