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

pub struct Collider2D {
  // handle
}

pub enum ColliderShape2D {
  Circle { radius: f32 },
  Rectangle { half_width: f32, half_height: f32 },
  Capsule { half_height: f32, radius: f32 },
  ConvexPolygon { vertices: Vec<[f32; 2]> },
}

pub struct Collider2DBuilder {
  shape: ColliderShape2D,
  offset: [f32; 2],
  density: f32,
  friction: f32,
  restitution: f32,
}

impl Collider2DBuilder {
  pub fn circle(radius: f32) -> Self;
  pub fn rectangle(half_width: f32, half_height: f32) -> Self;
  pub fn capsule(half_height: f32, radius: f32) -> Self;
  pub fn polygon(vertices: Vec<[f32; 2]>) -> Self;
  pub fn with_offset(self, x: f32, y: f32) -> Self;
  pub fn with_density(self, density: f32) -> Self;
  pub fn with_friction(self, friction: f32) -> Self;
  pub fn with_restitution(self, bounce: f32) -> Self;
  pub fn build(self, body: &mut RigidBody2D) -> 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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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