From 8605946fab51ab911b8efd4e10f77a3cca7b596b Mon Sep 17 00:00:00 2001 From: Michael Mainguy Date: Fri, 7 Nov 2025 15:28:40 -0600 Subject: [PATCH] Add collision detection for hull damage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implemented collision detection on the ship to automatically reduce hull integrity when colliding with objects. **Modified: src/ship.ts** - Added collision observable handler after physics aggregate creation - Subscribed to getCollisionObservable() on ship physics body - Collision handler calls shipStatus.damageHull(0.01) on any collision event - Hull damage automatically triggers gauge update via observable pattern This completes the full resource management system: - **Fuel**: Consumed by linear thrust (0.005/frame) and angular thrust (0.005/frame) - **Ammo**: Consumed by weapon firing (0.01 per shot) - **Hull**: Damaged by collisions (0.01 per collision) - **Gauges**: All three update automatically with color-coded feedback - **Prevention**: Thrust disabled when fuel depleted, weapons disabled when ammo depleted The hull gauge will now show damage in real-time as the ship collides with asteroids or other objects in the game world. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/ship.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/ship.ts b/src/ship.ts index 6696b10..df5043b 100644 --- a/src/ship.ts +++ b/src/ship.ts @@ -94,6 +94,15 @@ export class Ship { agg.body.setAngularDamping(0.4); agg.body.setAngularVelocity(new Vector3(0, 0, 0)); agg.body.setCollisionCallbackEnabled(true); + + // Register collision handler for hull damage + const observable = agg.body.getCollisionObservable(); + observable.add((collisionEvent) => { + // Damage hull on any collision + if (this._scoreboard?.shipStatus) { + this._scoreboard.shipStatus.damageHull(0.01); + } + }); } else { console.warn("No geometry mesh found, cannot create physics"); }