Add bullet on-impact despawning system

This commit is contained in:
2025-08-10 18:43:56 -05:00
parent 364fbd7530
commit cdd665cc93
2 changed files with 10 additions and 0 deletions

View File

@@ -55,6 +55,7 @@ impl Plugin for AsteroidPlugin {
physics::wrap_entities, physics::wrap_entities,
asteroids::tick_asteroid_manager, asteroids::tick_asteroid_manager,
asteroids::spawn_asteroid.after(asteroids::tick_asteroid_manager), asteroids::spawn_asteroid.after(asteroids::tick_asteroid_manager),
ship::bullet_impact_listener,
collision_listener, collision_listener,
// TODO: Remove debug printing // TODO: Remove debug printing
debug_collision_event_printer, debug_collision_event_printer,

View File

@@ -1,5 +1,6 @@
use crate::{ use crate::{
AngularVelocity, GameAssets, AngularVelocity, GameAssets,
event::BulletDestroy,
physics::{Velocity, Wrapping}, physics::{Velocity, Wrapping},
}; };
@@ -35,3 +36,11 @@ pub fn spawn_player(mut commands: Commands, game_assets: Res<GameAssets>) {
.with_translation(Vec3::new(-0.5, 0.0, -0.1)), .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<BulletDestroy>) {
for event in events.read() {
commands.entity(event.0).despawn();
}
}