Function avian3d::collision::contact_query::time_of_impact
source · pub fn time_of_impact(
collider1: &Collider,
position1: impl Into<Position>,
rotation1: impl Into<Rotation>,
velocity1: impl Into<LinearVelocity>,
collider2: &Collider,
position2: impl Into<Position>,
rotation2: impl Into<Rotation>,
velocity2: impl Into<LinearVelocity>,
max_time_of_impact: Scalar
) -> Result<Option<TimeOfImpact>, UnsupportedShape>
Expand description
Computes when two moving Collider
s hit each other for the first time.
Returns Ok(None)
if the time of impact is greater than max_time_of_impact
and Err(UnsupportedShape)
if either of the collider shapes is not supported.
§Example
use avian3d::prelude::{contact_query::time_of_impact, *};
use bevy::prelude::*;
let collider1 = Collider::sphere(0.5);
let collider2 = Collider::cuboid(1.0, 1.0, 1.0);
let result = time_of_impact(
&collider1, // Collider 1
Vec3::NEG_X * 5.0, // Position 1
Quat::default(), // Rotation 1
Vec3::X, // Linear velocity 1
&collider2, // Collider 2
Vec3::X * 5.0, // Position 2
Quat::default(), // Rotation 2
Vec3::NEG_X, // Linear velocity 2
100.0, // Maximum time of impact
)
.expect("Unsupported collider shape");
assert_eq!(result.unwrap().time_of_impact, 4.5);