Function avian3d::collision::contact_query::intersection_test

source ·
pub fn intersection_test(
    collider1: &Collider,
    position1: impl Into<Position>,
    rotation1: impl Into<Rotation>,
    collider2: &Collider,
    position2: impl Into<Position>,
    rotation2: impl Into<Rotation>
) -> Result<bool, UnsupportedShape>
Expand description

Tests whether two Colliders are intersecting each other.

Returns Err(UnsupportedShape) if either of the collider shapes is not supported.

§Example

use avian3d::prelude::{contact_query::intersection_test, *};
use bevy::prelude::*;

let collider1 = Collider::sphere(0.5);
let collider2 = Collider::cuboid(1.0, 1.0, 1.0);

// These colliders should be intersecting
assert_eq!(
    intersection_test(
        &collider1,
        Vec3::default(),
        Quat::default(),
        &collider2,
        Vec3::default(),
        Quat::default(),
    )
    .expect("Unsupported collider shape"),
    true,
);

// These colliders shouldn't be intersecting
assert_eq!(
    intersection_test(
        &collider1,
        Vec3::default(),
        Quat::default(),
        &collider2,
        Vec3::X * 5.0,
        Quat::default(),
    )
    .expect("Unsupported collider shape"),
    false,
);