diff --git a/README.md b/README.md index 694e6be..41b23c9 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ fn spawn_particle_system(mut commands: Commands, asset_server: Res) max_particles: 10_000, default_sprite: asset_server.load("my_particle.png"), spawn_rate_per_second: 25.0.into(), - initial_velocity: JitteredValue::jittered(3.0, -1.0..1.0), + initial_speed: JitteredValue::jittered(3.0, -1.0..1.0), lifetime: JitteredValue::jittered(8.0, -2.0..2.0), color: ColorOverTime::Gradient(Gradient::new(vec![ ColorPoint::new(Color::WHITE, 0.0), diff --git a/examples/basic.rs b/examples/basic.rs index 7eb828e..8d96da3 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -38,7 +38,7 @@ fn startup_system(mut commands: Commands, asset_server: Res) { max_particles: 50_000, default_sprite: asset_server.load("px.png"), spawn_rate_per_second: 1000.0.into(), - initial_velocity: JitteredValue::jittered(3.0, -1.0..1.0), + initial_speed: JitteredValue::jittered(3.0, -1.0..1.0), acceleration: ValueOverTime::Sin(SinWave { amplitude: 150.0, period: 5.0, diff --git a/examples/local_space.rs b/examples/local_space.rs index f2d1c53..7e7fbea 100644 --- a/examples/local_space.rs +++ b/examples/local_space.rs @@ -42,7 +42,7 @@ fn startup_system(mut commands: Commands, asset_server: Res) { emitter_angle: 0.0, default_sprite: asset_server.load("px.png"), spawn_rate_per_second: 35.0.into(), - initial_velocity: JitteredValue::jittered(25.0, 0.0..5.0), + initial_speed: JitteredValue::jittered(25.0, 0.0..5.0), acceleration: 0.0.into(), lifetime: JitteredValue::jittered(3.0, -2.0..2.0), color: ColorOverTime::Gradient(Gradient::new(vec![ @@ -69,7 +69,7 @@ fn startup_system(mut commands: Commands, asset_server: Res) { emitter_angle: std::f32::consts::PI, default_sprite: asset_server.load("px.png"), spawn_rate_per_second: 35.0.into(), - initial_velocity: JitteredValue::jittered(25.0, 0.0..5.0), + initial_speed: JitteredValue::jittered(25.0, 0.0..5.0), acceleration: 0.0.into(), lifetime: JitteredValue::jittered(3.0, -2.0..2.0), color: ColorOverTime::Gradient(Gradient::new(vec![ diff --git a/examples/time_scaling.rs b/examples/time_scaling.rs index 8bc5993..7cdf9c2 100644 --- a/examples/time_scaling.rs +++ b/examples/time_scaling.rs @@ -34,7 +34,7 @@ fn startup_system(mut commands: Commands, asset_server: Res) { emitter_angle: 0.0, default_sprite: asset_server.load("px.png"), spawn_rate_per_second: 35.0.into(), - initial_velocity: JitteredValue::jittered(25.0, 0.0..5.0), + initial_speed: JitteredValue::jittered(25.0, 0.0..5.0), acceleration: 0.0.into(), lifetime: JitteredValue::jittered(3.0, -2.0..2.0), color: ColorOverTime::Gradient(Gradient::new(vec![ @@ -61,7 +61,7 @@ fn startup_system(mut commands: Commands, asset_server: Res) { emitter_angle: std::f32::consts::PI, default_sprite: asset_server.load("px.png"), spawn_rate_per_second: 35.0.into(), - initial_velocity: JitteredValue::jittered(25.0, 0.0..5.0), + initial_speed: JitteredValue::jittered(25.0, 0.0..5.0), acceleration: 0.0.into(), lifetime: JitteredValue::jittered(3.0, -2.0..2.0), color: ColorOverTime::Gradient(Gradient::new(vec![ diff --git a/src/components.rs b/src/components.rs index ca27eb4..cef6d9e 100644 --- a/src/components.rs +++ b/src/components.rs @@ -81,14 +81,14 @@ pub struct ParticleSystem { /// Zero indicates straight to the right in the X direction. [`std::f32::consts::PI`] indicates straight left in the X direction. pub emitter_angle: f32, - /// The initial movement velocity of a particle. + /// The initial movement speed of a particle. /// /// This value can be constant, or have added jitter to have particles move at varying speeds. - pub initial_velocity: JitteredValue, + pub initial_speed: JitteredValue, /// The acceleration of each particle. /// - /// This value can change over time. Zero makes the particle move at its ``initial_velocity`` for its lifetime. + /// This value can change over time. Zero makes the particle move at its ``initial_speed`` for its lifetime. pub acceleration: ValueOverTime, /// The lifetime of each particle, in seconds. @@ -146,7 +146,7 @@ impl Default for ParticleSystem { spawn_radius: 0.0.into(), emitter_shape: std::f32::consts::TAU, emitter_angle: 0.0, - initial_velocity: 1.0.into(), + initial_speed: 1.0.into(), acceleration: 0.0.into(), lifetime: 5.0.into(), color: ColorOverTime::default(), @@ -205,9 +205,9 @@ pub struct Lifetime(pub f32); #[derive(Debug, Component, Default)] pub struct DistanceTraveled(pub f32); -/// Defines the current velocity of an individual particle entity. +/// Defines the current speed of an individual particle entity. #[derive(Debug, Component, Default)] -pub struct Velocity(pub f32); +pub struct Speed(pub f32); /// Defines the direction a particle is currently traveling. #[derive(Debug, Component, Default)] @@ -298,7 +298,7 @@ pub struct ParticleSystemBundle { pub(crate) struct ParticleBundle { pub particle: Particle, pub lifetime: Lifetime, - pub velocity: Velocity, + pub speed: Speed, pub direction: Direction, pub distance: DistanceTraveled, } diff --git a/src/lib.rs b/src/lib.rs index 00a65aa..9134f05 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -41,7 +41,7 @@ //! max_particles: 10_000, //! default_sprite: asset_server.load("my_particle.png"), //! spawn_rate_per_second: 25.0.into(), -//! initial_velocity: JitteredValue::jittered(3.0, -1.0..1.0), +//! initial_speed: JitteredValue::jittered(3.0, -1.0..1.0), //! lifetime: JitteredValue::jittered(8.0, -2.0..2.0), //! color: ColorOverTime::Gradient(Gradient::new(vec![ //! ColorPoint::new(Color::WHITE, 0.0), diff --git a/src/systems.rs b/src/systems.rs index 74c2844..a97df52 100644 --- a/src/systems.rs +++ b/src/systems.rs @@ -9,7 +9,7 @@ use rand::prelude::*; use crate::{ components::{ BurstIndex, Direction, Lifetime, Particle, ParticleBundle, ParticleCount, ParticleSpace, - ParticleSystem, Playing, RunningState, Velocity, + ParticleSystem, Playing, RunningState, Speed, }, values::ColorOverTime, DistanceTraveled, @@ -137,9 +137,7 @@ pub fn partcle_spawner( max_lifetime: particle_system.lifetime.get_value(&mut rng), max_distance: particle_system.max_distance, }, - velocity: Velocity( - particle_system.initial_velocity.get_value(&mut rng), - ), + speed: Speed(particle_system.initial_speed.get_value(&mut rng)), direction: Direction::new( direction, particle_system.z_value_override.is_some(), @@ -165,9 +163,7 @@ pub fn partcle_spawner( max_lifetime: particle_system.lifetime.get_value(&mut rng), max_distance: particle_system.max_distance, }, - velocity: Velocity( - particle_system.initial_velocity.get_value(&mut rng), - ), + speed: Speed(particle_system.initial_speed.get_value(&mut rng)), direction: Direction::new( direction, particle_system.z_value_override.is_some(), @@ -232,7 +228,7 @@ pub(crate) fn particle_transform( &Lifetime, &Direction, &mut DistanceTraveled, - &mut Velocity, + &mut Speed, &mut Transform, )>, particle_system_query: Query<&ParticleSystem>, @@ -240,18 +236,18 @@ pub(crate) fn particle_transform( ) { particle_query.par_for_each_mut( 512, - |(particle, lifetime, direction, mut distance, mut velocity, mut transform)| { + |(particle, lifetime, direction, mut distance, mut speed, mut transform)| { if let Ok(particle_system) = particle_system_query.get(particle.parent_system) { let lifetime_pct = lifetime.0 / particle.max_lifetime; let initial_position = transform.translation; if particle_system.use_scaled_time { - velocity.0 += particle_system.acceleration.at_lifetime_pct(lifetime_pct) + speed.0 += particle_system.acceleration.at_lifetime_pct(lifetime_pct) * time.delta_seconds(); - transform.translation += direction.0 * velocity.0 * time.delta_seconds(); + transform.translation += direction.0 * speed.0 * time.delta_seconds(); } else { - velocity.0 += particle_system.acceleration.at_lifetime_pct(lifetime_pct) + speed.0 += particle_system.acceleration.at_lifetime_pct(lifetime_pct) * time.raw_delta_seconds(); - transform.translation += direction.0 * velocity.0 * time.raw_delta_seconds(); + transform.translation += direction.0 * speed.0 * time.raw_delta_seconds(); } transform.scale = Vec3::splat(particle_system.scale.at_lifetime_pct(lifetime_pct));