Skip to content

[Feature] 2D collision detection and callbacks #121

Description

@vmarcella

Overview

Add collision detection queries and event callbacks so games can respond to
physics interactions between bodies.

Current State

No response

Scope

Goals:

  • Collision start/end events
  • Contact point information
  • Collision filtering (layers/masks)
  • Query overlapping bodies at a point
  • Intersection tests without simulation

Non-Goals:

  • Trigger volumes (separate issue)
  • Complex filtering rules (deferred)

Proposed API

pubstructCollisionEvent{pubbody_a:RigidBodyHandle,pubbody_b:RigidBodyHandle,pubcontact_point:[f32;2],pubnormal:[f32;2],pubpenetration:f32,}pubstructCollisionFilter{pubgroup:u32,pubmask:u32,}implPhysicsWorld2D{pubfncollision_events(&self) -> implIterator<Item = CollisionEvent>;pubfnquery_point(&self,point:[f32;2]) -> Vec<RigidBodyHandle>;pubfnquery_aabb(&self,min:[f32;2],max:[f32;2]) -> Vec<RigidBodyHandle>;pubfnraycast(&self,origin:[f32;2],dir:[f32;2],max_dist:f32) -> Option<RaycastHit>;}implCollider2DBuilder{pubfnwith_collision_filter(self,filter:CollisionFilter) -> Self;}

Acceptance Criteria

  • Collision events fire when bodies first touch
  • Collision events include contact information
  • Collision filters prevent specified pairs from colliding
  • Point queries find bodies containing that point
  • Raycasts return first hit with normal and distance

Affected Crates

lambda-rs, lambda-rs-platform

Notes

  • Events collected during step, consumed after
  • Filter: collide if (a.group & b.mask) && (b.group & a.mask)

Metadata

Metadata

Assignees

No one assigned

    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