Skip to content

[Feature] Persistent 2D contact events #203

@vmarcella

Description

@vmarcella

Overview

Add an optional persistent-contact event mode for PhysicsWorld2D so
gameplay code can observe pairs that remain in contact across consecutive
steps without reconstructing that state manually from Started and Ended.

Current State

The public API only exposes CollisionEventKind::{Started, Ended} in
crates/lambda-rs/src/physics/mod.rs. Users who need "stay" semantics must
cache active pairs in gameplay code and rebuild that view themselves.

Scope

Goals:

  • Add an explicit persistent-contact event shape or access pattern
  • Preserve the existing Started and Ended semantics
  • Keep the public API body-oriented by default
  • Define whether persistent events fire once per step or once per substep

Non-Goals:

  • Trigger volumes
  • Per-collider event streams as the default API
  • Contact impulse reporting in the first iteration

Proposed API

pub enum CollisionEventKind {
  Started,
  Stayed,
  Ended,
}

impl PhysicsWorld2D {
  pub fn collision_events(&self) -> impl Iterator<Item = CollisionEvent>;
}

Acceptance Criteria

  • A persistent-contact API is defined and documented
  • Compound-body aggregation still produces one body-pair event
  • Started fires once on contact begin
  • Persistent contact state is available on later touching steps
  • Ended fires once when the pair separates
  • Integration tests cover steady contact across multiple steps
  • Demo or tutorial coverage explains when to use this over
    Started/Ended

Affected Crates

lambda-rs, lambda-rs-platform

Notes

  • Adding Stayed directly to collision_events() increases event volume.
  • A separate iterator may be cleaner if most users only need enter/exit.
  • Deterministic ordering requirements should be defined before adding a
    steady-state event stream.

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