scene_queries_point_projection
Point projection will either project a point on the closest collider of the scene (QueryPipeline::project_point
RapierContext::project_point
World.projectPoint
QueryPipeline::intersections_with_point
RapierContext::intersections_with_point
World.intersectionsWithPoint
- Example 2D
- Example 3D
let point = point![1.0, 2.0];
let solid = true;
let filter = QueryFilter::default();
if let Some((handle, projection)) = query_pipeline.project_point(
rigid_body_set,
collider_set, &point, solid, filter
) {
// The collider closest to the point has this `handle`.
println!("Projected point on collider {:?}. Point projection: {}", handle, projection.point);
println!("Point was inside of the collider shape: {}", projection.is_inside);
}
query_pipeline.intersections_with_point(
rigid_body_set, collider_set, &point, filter, |handle| {
// Callback called on each collider with a shape containing the point.
println!("The collider {:?} contains the point.", handle);
// Return `false` instead if we want to stop searching for other colliders containing this point.
true
}
);
let point = point![1.0, 2.0, 3.0];
let solid = true;
let filter = QueryFilter::default();
if let Some((handle, projection)) = query_pipeline.project_point(
rigid_body_set, &collider_set, &point, solid, filter
) {
// The collider closest to the point has this `handle`.
println!("Projected point on collider {:?}. Point projection: {}", handle, projection.point);
println!("Point was inside of the collider shape: {}", projection.is_inside);
}
query_pipeline.intersections_with_point(
rigid_body_set, &collider_set, &point, filter, |handle| {
// Callback called on each collider with a shape containing the point.
println!("The collider {:?} contains the point.", handle);
// Return `false` instead if we want to stop searching for other colliders containing this point.
true
}
);
- Example 2D
- Example 3D
/* 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
});
}
/* Project a point inside of a system. */
fn project_point(rapier_context: Res<RapierContext>) {
let point = Vec3::new(1.0, 2.0, 3.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
});
}
- Example 2D
- Example 3D
let point = { x: 1.0, y: 2.0 };
let solid = true;
let proj = world.projectPoint(point, solid);
if (proj != null) {
// The collider closest to the point has this `handle`.
console.log("Projected point on collider ", proj.collider, ". Point projection: ", proj.point);
console.log("Point was inside of the collider shape: {}", proj.isInside);
}
world.intersectionsWithPoint(point, (handle) => {
// Callback called on each collider with a shape containing the point.
console.log("The collider", handle, "contains the point.");
// Return `false` instead if we want to stop searching for other colliders containing this point.
return true;
});
let point = { x: 1.0, y: 2.0, z: 3.0 };
let solid = true;
let proj = world.projectPoint(point, solid);
if (proj != null) {
// The collider closest to the point has this `handle`.
console.log("Projected point on collider ", proj.collider, ". Point projection: ", proj.point);
console.log("Point was inside of the collider shape: {}", proj.isInside);
}
world.intersectionsWithPoint(point, (handle) => {
// Callback called on each collider with a shape containing the point.
console.log("The collider", handle, "contains the point.");
// Return `false` instead if we want to stop searching for other colliders containing this point.
return true;
});
It is possible to only apply the scene query to a subsets of the colliders using a query filter