use std::{f32::consts::TAU, num::Wrapping, time::Duration}; use bevy::{ prelude::{shape::Capsule, *}, window::close_on_esc, }; use bevy_mod_outline::*; #[bevy_main] fn main() { App::new() .insert_resource(Msaa::Sample4) .insert_resource(ClearColor(Color::BLACK)) .add_plugins((DefaultPlugins, OutlinePlugin)) .add_systems(Startup, setup) .add_systems( Update, (close_on_esc, spawn_objects, move_objects, despawn_objects), ) .run(); } #[derive(Resource)] struct MyAssets { mesh: Handle, material: Handle, } #[derive(Component)] struct FlyingObject; fn setup( mut commands: Commands, mut meshes: ResMut>, mut materials: ResMut>, ) { commands.insert_resource(MyAssets { mesh: meshes.add(Mesh::from(Capsule { radius: 1.0, rings: 10, depth: 2.0, latitudes: 15, longitudes: 15, ..default() })), material: materials.add(StandardMaterial::from(Color::BEIGE)), }); // Add light source and camera commands.spawn(DirectionalLightBundle { directional_light: DirectionalLight { illuminance: 750.0, ..default() }, ..default() }); commands.spawn(Camera3dBundle { transform: Transform::from_xyz(0.0, 0.0, 50.0).looking_at(Vec3::ZERO, Vec3::Y), ..default() }); } struct SpawnState(Timer, Wrapping); impl Default for SpawnState { fn default() -> Self { let mut timer = Timer::from_seconds(0.75, TimerMode::Repeating); timer.tick(timer.duration() - Duration::from_nanos(1)); Self(timer, Wrapping(0)) } } fn spawn_objects( mut commands: Commands, mut timer: Local, time: Res