particles: fade out transparency over time
This commit is contained in:
parent
4f71f833fb
commit
7e7b8e7432
|
@ -430,6 +430,7 @@ pub fn apply_input_to_player(
|
||||||
(&Position, &LinearVelocity),
|
(&Position, &LinearVelocity),
|
||||||
(
|
(
|
||||||
Without<hud::IsTargeted>,
|
Without<hud::IsTargeted>,
|
||||||
|
Without<visual::IsEffect>,
|
||||||
Without<actor::PlayerCamera>,
|
Without<actor::PlayerCamera>,
|
||||||
Without<actor::Player>,
|
Without<actor::Player>,
|
||||||
Without<actor::PlayerDrivesThis>,
|
Without<actor::PlayerDrivesThis>,
|
||||||
|
@ -571,7 +572,7 @@ pub fn apply_input_to_player(
|
||||||
let thruster_direction = acceleration_total.normalize();
|
let thruster_direction = acceleration_total.normalize();
|
||||||
let thruster_v = v.0 - 10.0 * thruster_direction;
|
let thruster_v = v.0 - 10.0 * thruster_direction;
|
||||||
ew_effect.send(visual::SpawnEffectEvent {
|
ew_effect.send(visual::SpawnEffectEvent {
|
||||||
duration: 1.0,
|
duration: 2.0,
|
||||||
class: visual::Effects::ThrusterParticle(pos.clone(), LinearVelocity::from(thruster_v)),
|
class: visual::Effects::ThrusterParticle(pos.clone(), LinearVelocity::from(thruster_v)),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ impl Plugin for VisualPlugin {
|
||||||
app.add_systems(Update, spawn_effects);
|
app.add_systems(Update, spawn_effects);
|
||||||
app.add_systems(Update, update_fadein);
|
app.add_systems(Update, update_fadein);
|
||||||
app.add_systems(Update, update_fadeout);
|
app.add_systems(Update, update_fadeout);
|
||||||
|
app.add_systems(Update, update_fade_material);
|
||||||
app.add_systems(Update, update_grow);
|
app.add_systems(Update, update_grow);
|
||||||
app.add_systems(Update, play_animations);
|
app.add_systems(Update, play_animations);
|
||||||
// Blackout disabled for now
|
// Blackout disabled for now
|
||||||
|
@ -45,12 +46,19 @@ pub enum Effects {
|
||||||
// Blackout disabled for now
|
// Blackout disabled for now
|
||||||
//#[derive(Component)] pub struct BlackOutOverlay;
|
//#[derive(Component)] pub struct BlackOutOverlay;
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
pub struct IsEffect;
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub struct FadeInSprite;
|
pub struct FadeInSprite;
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub struct FadeOutSprite;
|
pub struct FadeOutSprite;
|
||||||
#[derive(Component)]
|
#[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)]
|
#[derive(Component)]
|
||||||
pub struct Grow3DObject {
|
pub struct Grow3DObject {
|
||||||
pub start_time: f64,
|
pub start_time: f64,
|
||||||
|
@ -131,6 +139,7 @@ pub fn spawn_effects(
|
||||||
match effect.class {
|
match effect.class {
|
||||||
Effects::FadeIn(color) => {
|
Effects::FadeIn(color) => {
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
|
IsEffect,
|
||||||
Effect {
|
Effect {
|
||||||
class: effect.class.clone(),
|
class: effect.class.clone(),
|
||||||
duration: effect.duration,
|
duration: effect.duration,
|
||||||
|
@ -146,6 +155,7 @@ pub fn spawn_effects(
|
||||||
}
|
}
|
||||||
Effects::FadeOut(color) => {
|
Effects::FadeOut(color) => {
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
|
IsEffect,
|
||||||
Effect {
|
Effect {
|
||||||
class: effect.class.clone(),
|
class: effect.class.clone(),
|
||||||
duration: effect.duration,
|
duration: effect.duration,
|
||||||
|
@ -162,6 +172,7 @@ pub fn spawn_effects(
|
||||||
Effects::ThrusterParticle(pos, v) => {
|
Effects::ThrusterParticle(pos, v) => {
|
||||||
let texture = asset_server.load("textures/exhaust.png");
|
let texture = asset_server.load("textures/exhaust.png");
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
|
IsEffect,
|
||||||
RigidBody::Kinematic,
|
RigidBody::Kinematic,
|
||||||
bevy::pbr::NotShadowCaster,
|
bevy::pbr::NotShadowCaster,
|
||||||
pos,
|
pos,
|
||||||
|
@ -170,9 +181,15 @@ pub fn spawn_effects(
|
||||||
start_time: now,
|
start_time: now,
|
||||||
duration: effect.duration,
|
duration: effect.duration,
|
||||||
scale_start: 1.0,
|
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,
|
world::DespawnOnPlayerDeath,
|
||||||
actor::WantsToLookAt(cmd::ID_SPECIAL_PLAYERCAM.into()),
|
actor::WantsToLookAt(cmd::ID_SPECIAL_PLAYERCAM.into()),
|
||||||
PbrBundle {
|
PbrBundle {
|
||||||
|
@ -180,6 +197,7 @@ pub fn spawn_effects(
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color_texture: Some(texture),
|
base_color_texture: Some(texture),
|
||||||
perceptual_roughness: 1.0,
|
perceptual_roughness: 1.0,
|
||||||
|
metallic: 0.5,
|
||||||
alpha_mode: AlphaMode::Blend,
|
alpha_mode: AlphaMode::Blend,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|
@ -223,6 +241,31 @@ pub fn update_fadeout(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn update_fade_material(
|
||||||
|
mut commands: Commands,
|
||||||
|
mut q_object: Query<(Entity, &Handle<StandardMaterial>, &FadeMaterial)>,
|
||||||
|
time: Res<Time>,
|
||||||
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||||
|
) {
|
||||||
|
let now = time.elapsed_seconds_f64();
|
||||||
|
for (entity, material_handle, data) in q_object.iter_mut() {
|
||||||
|
let end_time = data.start_time + data.duration;
|
||||||
|
let material = materials.get_mut(material_handle).unwrap();
|
||||||
|
if now > end_time {
|
||||||
|
material.base_color.set_alpha(data.value_end);
|
||||||
|
commands.entity(entity).remove::<FadeMaterial>();
|
||||||
|
}
|
||||||
|
else if now < data.start_time {
|
||||||
|
material.base_color.set_alpha(data.value_start);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
let progress = ((now - data.start_time) / data.duration) as f32;
|
||||||
|
let value = data.value_start + progress * (data.value_end - data.value_start);
|
||||||
|
material.base_color.set_alpha(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn update_grow(
|
pub fn update_grow(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
mut q_object: Query<(Entity, &mut Transform, &Grow3DObject)>,
|
mut q_object: Query<(Entity, &mut Transform, &Grow3DObject)>,
|
||||||
|
@ -242,7 +285,6 @@ pub fn update_grow(
|
||||||
let progress = ((now - data.start_time) / data.duration) as f32;
|
let progress = ((now - data.start_time) / data.duration) as f32;
|
||||||
let scale = data.scale_start + progress * (data.scale_end - data.scale_start);
|
let scale = data.scale_start + progress * (data.scale_end - data.scale_start);
|
||||||
trans.scale = Vec3::splat(scale);
|
trans.scale = Vec3::splat(scale);
|
||||||
dbg!(progress, scale, trans.scale);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue