Skip to content

[Feature] 2D collision shapes #120

Description

@vmarcella

Overview

Add collision shapes that can be attached to rigid bodies to enable collision
detection. Support common 2D primitives.

Current State

No collision shapes exist & requires rigid bodies to be implemented.

Scope

Goals:

  • Circle collider (position, radius)
  • Rectangle/box collider (half-extents)
  • Capsule collider (height, radius)
  • Convex polygon collider
  • Attach multiple shapes to one body

Non-Goals:

  • Concave/decomposed shapes (deferred)
  • Collision detection callbacks
  • Collision layers/masks

Proposed API

pubstructCollider2D{// handle}pubenumColliderShape2D{Circle{radius:f32},Rectangle{half_width:f32,half_height:f32},Capsule{half_height:f32,radius:f32},ConvexPolygon{vertices:Vec<[f32;2]>},}pubstructCollider2DBuilder{shape:ColliderShape2D,offset:[f32;2],density:f32,friction:f32,restitution:f32,}implCollider2DBuilder{pubfncircle(radius:f32) -> Self;pubfnrectangle(half_width:f32,half_height:f32) -> Self;pubfncapsule(half_height:f32,radius:f32) -> Self;pubfnpolygon(vertices:Vec<[f32;2]>) -> Self;pubfnwith_offset(self,x:f32,y:f32) -> Self;pubfnwith_density(self,density:f32) -> Self;pubfnwith_friction(self,friction:f32) -> Self;pubfnwith_restitution(self,bounce:f32) -> Self;pubfnbuild(self,body:&mutRigidBody2D) -> Collider2D;}

Acceptance Criteria

  • Circle colliders detect collisions correctly
  • Rectangle colliders detect collisions correctly
  • Capsule colliders work for character shapes
  • Polygon colliders support arbitrary convex shapes
  • Multiple colliders on one body work together
  • Friction and restitution affect collision response

Affected Crates

lambda-rs, lambda-rs-platform

Notes

  • Density affects mass calculation
  • Restitution: 0 = no bounce, 1 = perfect bounce
  • Friction: 0 = ice, 1 = high grip

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