From cdd665cc93478062b9674d0450e2cf2681631917 Mon Sep 17 00:00:00 2001 From: Robert Garrett Date: Sun, 10 Aug 2025 18:43:56 -0500 Subject: [PATCH] Add bullet on-impact despawning system --- src/lib.rs | 1 + src/ship.rs | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index f9ba9c3..f287a64 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -55,6 +55,7 @@ impl Plugin for AsteroidPlugin { physics::wrap_entities, asteroids::tick_asteroid_manager, asteroids::spawn_asteroid.after(asteroids::tick_asteroid_manager), + ship::bullet_impact_listener, collision_listener, // TODO: Remove debug printing debug_collision_event_printer, diff --git a/src/ship.rs b/src/ship.rs index b2eeda2..b76920b 100644 --- a/src/ship.rs +++ b/src/ship.rs @@ -1,5 +1,6 @@ use crate::{ AngularVelocity, GameAssets, + event::BulletDestroy, physics::{Velocity, Wrapping}, }; @@ -35,3 +36,11 @@ pub fn spawn_player(mut commands: Commands, game_assets: Res) { .with_translation(Vec3::new(-0.5, 0.0, -0.1)), )); } + +/// Watch for [`BulletDestroy`] events and despawn +/// the associated bullet. +pub fn bullet_impact_listener(mut commands: Commands, mut events: EventReader) { + for event in events.read() { + commands.entity(event.0).despawn(); + } +}