despawn asteroids only when they're 1km+ away

This commit is contained in:
yuni 2024-04-24 04:36:49 +02:00
parent 656d7f02f0
commit 4c316e36a6

View file

@ -172,7 +172,7 @@ fn spawn_despawn_asteroids(
q_player: Query<&Position, With<actor::PlayerCamera>>,
mut ew_despawn: EventWriter<DespawnEvent>,
mut db: ResMut<ActiveAsteroids>,
mut q_asteroid: Query<&SceneInstance, With<Asteroid>>,
q_asteroid: Query<(&Position, &SceneInstance), With<Asteroid>>,
mut last_player_cell: Local<I64Vec3>,
id2pos: Res<actor::Id2Pos>,
asset_server: Res<AssetServer>,
@ -216,12 +216,14 @@ fn spawn_despawn_asteroids(
|| origin.y < y_min || origin.y > y_max
|| origin.z < z_min || origin.z > z_max
{
if let Ok(sceneinstance) = q_asteroid.get(asteroid.entity) {
ew_despawn.send(DespawnEvent {
entity: asteroid.entity,
sceneinstance: **sceneinstance,
origin: origin.clone(),
});
if let Ok((pos, sceneinstance)) = q_asteroid.get(asteroid.entity) {
if pos.0.distance(player.0) > 1000.0 {
ew_despawn.send(DespawnEvent {
entity: asteroid.entity,
sceneinstance: **sceneinstance,
origin: origin.clone(),
});
}
} else {
error!("Couldn't despawn asteroid:");
dbg!(origin);