Skip to main content

scene_queries_point_projection

Point projection will either project a point on the closest collider of the scene (World.projectPoint), or will enumerate every collider containing given point (World.intersectionsWithPoint).

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;
});

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