From 7e7b8e74325d63389360a6a92d6d135a46504a56 Mon Sep 17 00:00:00 2001 From: yuni Date: Mon, 16 Sep 2024 01:17:43 +0200 Subject: [PATCH] particles: fade out transparency over time --- src/camera.rs | 3 ++- src/visual.rs | 50 ++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/src/camera.rs b/src/camera.rs index 6cc0bb2..ff5b6bf 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -430,6 +430,7 @@ pub fn apply_input_to_player( (&Position, &LinearVelocity), ( Without, + Without, Without, Without, Without, @@ -571,7 +572,7 @@ pub fn apply_input_to_player( let thruster_direction = acceleration_total.normalize(); let thruster_v = v.0 - 10.0 * thruster_direction; ew_effect.send(visual::SpawnEffectEvent { - duration: 1.0, + duration: 2.0, class: visual::Effects::ThrusterParticle(pos.clone(), LinearVelocity::from(thruster_v)), }); } diff --git a/src/visual.rs b/src/visual.rs index 2eec69f..6afcd24 100644 --- a/src/visual.rs +++ b/src/visual.rs @@ -27,6 +27,7 @@ impl Plugin for VisualPlugin { app.add_systems(Update, spawn_effects); app.add_systems(Update, update_fadein); app.add_systems(Update, update_fadeout); + app.add_systems(Update, update_fade_material); app.add_systems(Update, update_grow); app.add_systems(Update, play_animations); // Blackout disabled for now @@ -45,12 +46,19 @@ pub enum Effects { // Blackout disabled for now //#[derive(Component)] pub struct BlackOutOverlay; +#[derive(Component)] +pub struct IsEffect; #[derive(Component)] pub struct FadeInSprite; #[derive(Component)] pub struct FadeOutSprite; #[derive(Component)] -pub struct FadeOut3DObject; +pub struct FadeMaterial { + pub start_time: f64, + pub duration: f64, + pub value_start: f32, + pub value_end: f32, +} #[derive(Component)] pub struct Grow3DObject { pub start_time: f64, @@ -131,6 +139,7 @@ pub fn spawn_effects( match effect.class { Effects::FadeIn(color) => { commands.spawn(( + IsEffect, Effect { class: effect.class.clone(), duration: effect.duration, @@ -146,6 +155,7 @@ pub fn spawn_effects( } Effects::FadeOut(color) => { commands.spawn(( + IsEffect, Effect { class: effect.class.clone(), duration: effect.duration, @@ -162,6 +172,7 @@ pub fn spawn_effects( Effects::ThrusterParticle(pos, v) => { let texture = asset_server.load("textures/exhaust.png"); commands.spawn(( + IsEffect, RigidBody::Kinematic, bevy::pbr::NotShadowCaster, pos, @@ -170,9 +181,15 @@ pub fn spawn_effects( start_time: now, duration: effect.duration, scale_start: 1.0, - scale_end: 10.0, + scale_end: 20.0, }, - world::DespawnAt(now + effect.duration * 3.0), + FadeMaterial { + start_time: now, + duration: effect.duration, + value_start: 0.1, + value_end: 0.0, + }, + world::DespawnAt(now + effect.duration), world::DespawnOnPlayerDeath, actor::WantsToLookAt(cmd::ID_SPECIAL_PLAYERCAM.into()), PbrBundle { @@ -180,6 +197,7 @@ pub fn spawn_effects( material: materials.add(StandardMaterial { base_color_texture: Some(texture), perceptual_roughness: 1.0, + metallic: 0.5, alpha_mode: AlphaMode::Blend, ..Default::default() }), @@ -223,6 +241,31 @@ pub fn update_fadeout( } } +pub fn update_fade_material( + mut commands: Commands, + mut q_object: Query<(Entity, &Handle, &FadeMaterial)>, + time: Res