@@ 25,7 25,7 @@ fn spawn_particles(
commands.spawn((
RigidBody::Dynamic,
Particle,
- transform.with_scale(Vec3::splat(1.0)),
+ transform.with_scale(Vec3::splat(effect.scale.sample(effect.scale.clamp_time(0.0).unwrap()).unwrap())),
Mesh2d(circle.0.clone()),
MeshMaterial2d(circle.1.clone()),
Velocity {
@@ 44,13 44,14 @@ fn spawn_particles(
fn lifetime_particles(
mut commands: Commands,
- mut particles: Query<(Entity, &mut LifetimeTimer, &CircleMesh, &ParentEffect), With<Particle>>,
+ mut particles: Query<(Entity, &mut LifetimeTimer, &mut Transform, &CircleMesh, &ParentEffect), With<Particle>>,
time: ResMut<Time>,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<ColorMaterial>>,
) {
- for (entity, mut timer, circle, parent) in &mut particles {
+ for (entity, mut timer, mut transform, circle, parent) in &mut particles {
timer.0.tick(time.delta());
+ transform.scale = Vec3::splat(parent.0.scale.sample(parent.0.scale.clamp_time(timer.0.elapsed_secs()).unwrap()).unwrap());
materials.get_mut(&circle.1).unwrap().color = parent.0.color.sample(parent.0.color.clamp_time(timer.0.elapsed_secs()).unwrap()).unwrap();
if timer.0.just_finished() {
commands.entity(entity).despawn();
@@ 1,5 1,5 @@
use std::collections::BTreeMap;
-use std::ops::Bound::{Included, Unbounded};
+use std::ops::Bound::{Included, Excluded, Unbounded};
use bevy::color::{Color, LinearRgba};
use bevy::math::Vec2;
use bevy::prelude::Component;
@@ 47,17 47,25 @@ impl<P: Lerp + Copy> LifetimeCurve<P> {
/// the domain of the points specified.
pub fn sample(&self, at: f32) -> Option<P> {
if self.0.is_empty() { return None; }
+
+ if self.0.len() == 1 && at == self.0.iter().nth(0).unwrap().0.0 {
+ return Some(*self.0.iter().nth(0).unwrap().1);
+ }
// Find A, the point "to the left" of `at`
- let mut r1 = self.0.range((Included(OrderedFloat(at)), Unbounded));
- let (a_key, a_val) = r1.next()?;
+ let mut r1 = self.0.range((Unbounded, Included(OrderedFloat(at))));
+ let (a_key, a_val) = r1.next_back()?;
- // Find B, the point "to the right" of `at`
- let mut r2 = self.0.range((Unbounded, Included(OrderedFloat(at))));
- let (b_key, b_val) = r2.next()?;
+ let (b_key, b_val) = if at == self.0.iter().last().unwrap().0.0 {
+ self.0.iter().last().unwrap()
+ } else {
+ // Find B, the point "to the right" of `at`
+ let mut r2 = self.0.range((Excluded(OrderedFloat(at)), Unbounded));
+ r2.next()?
+ };
// Calculate `t` (value from 0 - 1 indicating our progress from A to B)
- let t = at - *(a_key / (b_key - a_key));
+ let t = (at - **a_key) / *(b_key - a_key);
// Lerp
Some(a_val.lerp(b_val, t))