Skip to main content

scene_queries_point_projection

Point projection will either project a point on the closest collider of the scene (RapierContext::project_point), or will enumerate every collider containing given point (RapierContext::intersections_with_point).

/* Project a point inside of a system. */
fn project_point(rapier_context: Res<RapierContext>) {
let point = Vec2::new(1.0, 2.0);
let solid = true;
let filter = QueryFilter::default();

if let Some((entity, projection)) = rapier_context.project_point(point, solid, filter) {
// The collider closest to the point has this `handle`.
println!(
"Projected point on entity {:?}. Point projection: {}",
entity, projection.point
);
println!(
"Point was inside of the collider shape: {}",
projection.is_inside
);
}

rapier_context.intersections_with_point(point, filter, |entity| {
// Callback called on each collider with a shape containing the point.
println!("The entity {:?} contains the point.", entity);
// Return `false` instead if we want to stop searching for other colliders containing this point.
true
});
}

It is possible to only apply the scene query to a subsets of the colliders using a query filter