Skip to content

[Feature] Query-side filtering for 2D spatial queries #205

@vmarcella

Description

@vmarcella

Overview

Add query-side filtering so gameplay systems can restrict point queries, AABB
queries, and raycasts to selected collision groups or ignore specific bodies
without mutating collider-owned filter state.

Current State

query_point(), query_aabb(), and raycast() in
crates/lambda-rs/src/physics/mod.rs query all visible colliders and return
body-oriented results. There is no way to ask "only world geometry" or
"ignore the player" through the public API.

Scope

Goals:

  • Add query configuration for groups, masks, and ignored bodies
  • Preserve simple convenience overloads for the common no-filter case
  • Keep query behavior read-only and backend-agnostic
  • Define how query filters compose with collider-owned filters

Non-Goals:

  • Arbitrary user-provided predicate callbacks in the first iteration
  • Trigger volumes
  • Per-shape query callbacks

Proposed API

pub struct QueryFilter2D {
  pub group: Option<u32>,
  pub mask: Option<u32>,
  pub ignore_bodies: Vec<RigidBody2D>,
}

impl PhysicsWorld2D {
  pub fn query_point_filtered(
    &self,
    point: [f32; 2],
    filter: &QueryFilter2D,
  ) -> Vec<RigidBody2D>;

  pub fn query_aabb_filtered(
    &self,
    min: [f32; 2],
    max: [f32; 2],
    filter: &QueryFilter2D,
  ) -> Vec<RigidBody2D>;

  pub fn raycast_filtered(
    &self,
    origin: [f32; 2],
    dir: [f32; 2],
    max_dist: f32,
    filter: &QueryFilter2D,
  ) -> Option<RaycastHit>;
}

Acceptance Criteria

  • Point, AABB, and ray queries support explicit query-side filters
  • Query-side filters are documented independently from collider-owned
    collision filters
  • Ignored bodies are excluded reliably, including compound bodies
  • Existing unfiltered query methods retain current behavior
  • Integration tests cover layer/mask restriction and ignored-body cases
  • Docs explain common gameplay patterns for filtered queries

Affected Crates

lambda-rs-platform, lambda-rs

Notes

  • A small fixed-capacity ignore set may be useful later for hot paths.
  • Query filtering should not silently mutate or reinterpret collider-owned
    collision filters.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestlambda-rsIssues pertaining to the core frameworklambda-rs-platformIssues pertaining to the dependency & platform wrappersphysicsAll things related to physics

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions