diff options
| author | Kai Stevenson <kai@kaistevenson.com> | 2026-08-23 00:29:26 -0700 |
|---|---|---|
| committer | Kai Stevenson <kai@kaistevenson.com> | 2026-08-23 00:29:26 -0700 |
| commit | a0ff76837ca7ed6bd90cedcfee3832c1d9ad2287 (patch) | |
| tree | 413e574f0b5f41fafc6ced91d3d7bb2d0462237e /src/sim/entity | |
| parent | 4380928861c2a43f0d0b9793b9e501c720cf5803 (diff) | |
steel and collider mass
Diffstat (limited to 'src/sim/entity')
| -rw-r--r-- | src/sim/entity/entities/entity_grenade.rs | 2 | ||||
| -rw-r--r-- | src/sim/entity/mod.rs | 24 |
2 files changed, 17 insertions, 9 deletions
diff --git a/src/sim/entity/entities/entity_grenade.rs b/src/sim/entity/entities/entity_grenade.rs index abc57d9..952fb14 100644 --- a/src/sim/entity/entities/entity_grenade.rs +++ b/src/sim/entity/entities/entity_grenade.rs @@ -39,7 +39,7 @@ pub fn entity_grenade_def(position: Vec2, fuse: f32) -> EntityDef { for x in 0..w { for y in 0..h { let cell_idx = x + y * w; - raw_cells[cell_idx as usize] = Cell::from_material(MaterialId::Wood); + raw_cells[cell_idx as usize] = Cell::from_material(MaterialId::Steel); raw_cells[cell_idx as usize].set_entity(true); } } diff --git a/src/sim/entity/mod.rs b/src/sim/entity/mod.rs index 555d2c6..0f4ae3c 100644 --- a/src/sim/entity/mod.rs +++ b/src/sim/entity/mod.rs @@ -5,7 +5,7 @@ use rapier2d::{ }; use crate::{ - config::CELLS_TO_METRES, + config::{CELLS_TO_METRES, MASS_SCALING}, sim::{ cell::{cell::Cell, materials::MaterialId}, lib::marching_squares::Marchable, @@ -48,16 +48,16 @@ impl Marchable for EntityCells { pub trait EntityBehaviour { fn update( &mut self, - update_ctx: &mut EntityUpdateCtx, - ctx: &mut SimCtx, - delta_time: f32, + _update_ctx: &mut EntityUpdateCtx, + _ctx: &mut SimCtx, + _delta_time: f32, ) -> () { } fn physics_update( &mut self, - update_ctx: &mut EntityUpdateCtx, - ctx: &mut SimCtx, - delta_time: f32, + _update_ctx: &mut EntityUpdateCtx, + _ctx: &mut SimCtx, + _delta_time: f32, ) -> () { } } @@ -79,7 +79,15 @@ impl EntityDef { .translation(position / CELLS_TO_METRES) .build(); - let collider = RbManager::convex_hull_collider_from_marchable(&cells, None).build(); + let mass = cells + .cells + .iter() + .fold(0, |acc, cur| acc + cur.material.def().density) as f32 + * MASS_SCALING; + + let collider = RbManager::convex_hull_collider_from_marchable(&cells, None) + .mass(mass) + .build(); EntityDef { rb: Some(rb), |
