Add bullet on-impact despawning system
This commit is contained in:
@@ -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,
|
||||||
|
|||||||
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user