diff options
| author | Kai Stevenson <kai@kaistevenson.com> | 2026-08-23 02:48:43 -0700 |
|---|---|---|
| committer | Kai Stevenson <kai@kaistevenson.com> | 2026-08-23 02:48:43 -0700 |
| commit | 80824a8b69b70e6e40577e4f0236c28c4ad5c15b (patch) | |
| tree | bf3b72331c4ed9195bbe72d25d5e82c076d3220a /src/sim/particle_manager | |
| parent | d6664b9b5a9a3aab500b547e4d7448a8bc4ad416 (diff) | |
explosions affect rigidbodies, use "world" for rapier
Diffstat (limited to 'src/sim/particle_manager')
| -rw-r--r-- | src/sim/particle_manager/mod.rs | 10 | ||||
| -rw-r--r-- | src/sim/particle_manager/particle.rs | 10 |
2 files changed, 18 insertions, 2 deletions
diff --git a/src/sim/particle_manager/mod.rs b/src/sim/particle_manager/mod.rs index 052369b..559bf2c 100644 --- a/src/sim/particle_manager/mod.rs +++ b/src/sim/particle_manager/mod.rs @@ -2,7 +2,7 @@ use crate::{ config::CELLS_TO_METRES, content::materials::MaterialForm, sim::{ - cell::cell::Cell, cell_manager::manager::CellManager, lib::ray::AwDda, + cell::Cell, cell_manager::manager::CellManager, lib::ray::AwDda, particle_manager::particle::Particle, }, }; @@ -23,6 +23,7 @@ impl ParticleManager { let p = &mut self.particles[i]; p.life -= delta_time; + p.collision_grace -= delta_time; if p.life <= 0.0 { self.particles.swap_remove(i); continue 'outer; @@ -31,6 +32,13 @@ impl ParticleManager { p.velocity.y += PARTICLE_GRAVITY * delta_time; let dt_velocity = p.velocity * delta_time; + if p.collision_grace > 0.0 { + p.position += dt_velocity; + i += 1; + continue 'outer; + } + + // compute collisions let mut dda = AwDda::new(p.position, p.position + dt_velocity); if let Some(mut prev) = dda.next() { diff --git a/src/sim/particle_manager/particle.rs b/src/sim/particle_manager/particle.rs index c68d81e..279eacb 100644 --- a/src/sim/particle_manager/particle.rs +++ b/src/sim/particle_manager/particle.rs @@ -7,15 +7,23 @@ pub struct Particle { pub velocity: Vec2, pub material: MaterialId, pub life: f32, + pub collision_grace: f32, } impl Particle { - pub fn new(position: Vec2, velocity: Vec2, material: MaterialId, life: f32) -> Self { + pub fn new( + position: Vec2, + velocity: Vec2, + material: MaterialId, + life: f32, + collision_grace: f32, + ) -> Self { Particle { position, velocity, material, life, + collision_grace, } } } |
