-
Notifications
You must be signed in to change notification settings - Fork 2
[Feature] 2D collision detection and callbacks #121
Copy link
Copy link
Labels
enhancementNew feature or requestNew feature or requestlambda-rsIssues pertaining to the core frameworkIssues pertaining to the core frameworklambda-rs-platformIssues pertaining to the dependency & platform wrappersIssues pertaining to the dependency & platform wrappersphysicsAll things related to physicsAll things related to physics
Description
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
pub struct CollisionEvent {
pub body_a: RigidBodyHandle,
pub body_b: RigidBodyHandle,
pub contact_point: [f32; 2],
pub normal: [f32; 2],
pub penetration: f32,
}
pub struct CollisionFilter {
pub group: u32,
pub mask: u32,
}
impl PhysicsWorld2D {
pub fn collision_events(&self) -> impl Iterator<Item = CollisionEvent>;
pub fn query_point(&self, point: [f32; 2]) -> Vec<RigidBodyHandle>;
pub fn query_aabb(&self, min: [f32; 2], max: [f32; 2]) -> Vec<RigidBodyHandle>;
pub fn raycast(&self, origin: [f32; 2], dir: [f32; 2], max_dist: f32)
-> Option<RaycastHit>;
}
impl Collider2DBuilder {
pub fn with_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)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestlambda-rsIssues pertaining to the core frameworkIssues pertaining to the core frameworklambda-rs-platformIssues pertaining to the dependency & platform wrappersIssues pertaining to the dependency & platform wrappersphysicsAll things related to physicsAll things related to physics