fix despawning of scene-based asteroids, turn them back from spheres to scenes
This commit is contained in:
parent
ca0b2d9b96
commit
cfbd23f485
19
src/world.rs
19
src/world.rs
|
@ -11,7 +11,7 @@ const ASTEROID_SIZE: f32 = 100.0;
|
|||
const STARS_MAX_MAGNITUDE: f32 = 5.5;
|
||||
|
||||
const CENTER_WORLD_ON_PLAYER: bool = true;
|
||||
const ASTEROIDS_ARE_SPHERES: bool = true;
|
||||
const ASTEROIDS_ARE_SPHERES: bool = false;
|
||||
|
||||
const ASSET_ASTEROID1: &str = "models/asteroid.glb#Scene0";
|
||||
const ASSET_ASTEROID2: &str = "models/asteroid2.glb#Scene0";
|
||||
|
@ -36,6 +36,7 @@ impl Plugin for WorldPlugin {
|
|||
app.add_systems(Startup, setup);
|
||||
app.add_systems(Startup, generate_asteroids);
|
||||
app.add_systems(Update, handle_cheats);
|
||||
app.add_systems(PostUpdate, handle_despawn);
|
||||
app.add_systems(Update, spawn_despawn_asteroids);
|
||||
app.add_plugins(PhysicsPlugins::default());
|
||||
app.add_plugins(MaterialPlugin::<RingMaterial>::default());
|
||||
|
@ -44,6 +45,7 @@ impl Plugin for WorldPlugin {
|
|||
app.insert_resource(AsteroidUpdateTimer(
|
||||
Timer::from_seconds(ASTEROID_UPDATE_INTERVAL, TimerMode::Repeating)));
|
||||
app.insert_resource(AsteroidDatabase(Vec::new()));
|
||||
app.add_event::<DespawnEvent>();
|
||||
|
||||
if CENTER_WORLD_ON_PLAYER {
|
||||
// Disable bevy_xpbd's position->transform sync function
|
||||
|
@ -71,6 +73,9 @@ struct AsteroidData {
|
|||
pos: DVec3,
|
||||
}
|
||||
|
||||
#[derive(Event)]
|
||||
pub struct DespawnEvent(Entity);
|
||||
|
||||
#[derive(Asset, TypePath, AsBindGroup, Debug, Clone)]
|
||||
pub struct RingMaterial {
|
||||
alpha_mode: AlphaMode,
|
||||
|
@ -207,6 +212,7 @@ fn spawn_despawn_asteroids(
|
|||
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||
asset_server: Res<AssetServer>,
|
||||
mut log: ResMut<hud::Log>,
|
||||
mut ew_despawn: EventWriter<DespawnEvent>,
|
||||
) {
|
||||
if !timer.0.tick(time.delta()).just_finished() || q_player.is_empty() {
|
||||
return;
|
||||
|
@ -230,7 +236,7 @@ fn spawn_despawn_asteroids(
|
|||
asteroid.entity = None;
|
||||
asteroid.is_spawned = false;
|
||||
despawned += 1;
|
||||
commands.entity(entity).despawn();
|
||||
ew_despawn.send(DespawnEvent(entity));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -291,6 +297,15 @@ fn spawn_despawn_asteroids(
|
|||
}
|
||||
}
|
||||
|
||||
fn handle_despawn(
|
||||
mut commands: Commands,
|
||||
mut er_despawn: EventReader<DespawnEvent>,
|
||||
) {
|
||||
for despawn in er_despawn.read() {
|
||||
commands.entity(despawn.0).despawn();
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_cheats(
|
||||
mut commands: Commands,
|
||||
key_input: Res<ButtonInput<KeyCode>>,
|
||||
|
|
Loading…
Reference in a new issue