Skip to content

Commit

Permalink
Fix bug where particle velocity was not correctly calculated based on…
Browse files Browse the repository at this point in the history
… time (#8)

* Fix bug where particle velocity was not correctly calculated based on time

* Formatting
  • Loading branch information
abnormalbrain authored Jun 16, 2022
1 parent 2b11b88 commit 4394532
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
10 changes: 9 additions & 1 deletion examples/basic.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use bevy::{
core_pipeline::ClearColor,
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
prelude::{App, AssetServer, Color, Commands, OrthographicCameraBundle, Res},
window::{PresentMode, WindowDescriptor},
DefaultPlugins,
};
use bevy_particle_systems::{
Expand All @@ -11,6 +13,12 @@ use bevy_particle_systems::{
fn main() {
App::new()
.insert_resource(ClearColor(Color::BLACK))
.insert_resource(WindowDescriptor {
present_mode: PresentMode::Immediate,
..WindowDescriptor::default()
})
.add_plugin(FrameTimeDiagnosticsPlugin::default())
.add_plugin(LogDiagnosticsPlugin::default())
.add_plugins(DefaultPlugins)
.add_plugin(ParticleSystemPlugin::default()) // <-- Add the plugin
.add_startup_system(startup_system)
Expand All @@ -28,7 +36,7 @@ fn startup_system(mut commands: Commands, asset_server: Res<AssetServer>) {
spawn_rate_per_second: 500.0.into(),
initial_velocity: JitteredValue::jittered(3.0, -1.0..1.0),
acceleration: ValueOverTime::Sin(SinWave {
amplitude: 5.0,
amplitude: 150.0,
period: 5.0,
..SinWave::default()
}),
Expand Down
3 changes: 2 additions & 1 deletion src/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,8 @@ pub(crate) fn particle_transform(
}
}
let lifetime_pct = lifetime.0 / particle.max_lifetime;
velocity.0 += particle_system.acceleration.at_lifetime_pct(lifetime_pct);
velocity.0 += particle_system.acceleration.at_lifetime_pct(lifetime_pct)
* time.delta_seconds();
let initial_position = transform.translation;

transform.translation +=
Expand Down

0 comments on commit 4394532

Please sign in to comment.