From bb73b1ed1d8d899bc8bceca53c49691377a241f0 Mon Sep 17 00:00:00 2001 From: hut Date: Fri, 29 Mar 2024 18:20:12 +0100 Subject: [PATCH] implement collider/mass commands --- src/defs.txt | 7 +++++++ src/world.rs | 41 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/defs.txt b/src/defs.txt index afc4451..72096d0 100644 --- a/src/defs.txt +++ b/src/defs.txt @@ -12,6 +12,11 @@ actor 1000 20 300 monolith rotationx 0.5 angularmomentum 0.0 0.0 0.01 +actor 10 20 30 monolith + scale 2 + rotationx 0.5 + angularmomentum 0.0 0.0 0.01 + actor 10000 2000 -3500 monolith scale 2 rotationx 0.5 @@ -97,6 +102,8 @@ actor 10 -30 20 MeteorAceGT vehicle yes thrust 70 13.7 9.4 0.5 20 engine ion + collider sphere 2 + mass 500 actor 10 0 70 suit name Icarus diff --git a/src/world.rs b/src/world.rs index e8bf408..68e545f 100644 --- a/src/world.rs +++ b/src/world.rs @@ -87,6 +87,7 @@ pub fn setup( RigidBody::Dynamic, AngularVelocity(Vec3::new(0.0, 0.0, 0.0)), Collider::cuboid(1.0, 1.0, 1.0), + ColliderDensity(200.0), actor::Actor { angular_momentum: Quat::IDENTITY, ..default() @@ -255,6 +256,8 @@ struct ParserState { warmup_seconds: f32, engine_type: actor::EngineType, oxygen: f32, + mass: f32, + collider: Collider, // Chat fields delay: f64, @@ -295,6 +298,8 @@ impl Default for ParserState { warmup_seconds: default_engine.warmup_seconds, engine_type: default_engine.engine_type, oxygen: nature::OXY_D, + mass: 1.0, + collider: Collider::sphere(1.0), delay: 0.0, text: "".to_string(), @@ -366,6 +371,13 @@ impl ParserState { scene: asset_server.load(asset_name_to_path(self.model.as_str())), ..default() }); + + // Physics Parameters + let fix_scale = 1.0 / self.model_scale.powf(3.0); + actor.insert(RigidBody::Dynamic); + actor.insert(self.collider.clone()); + actor.insert(ColliderDensity(self.mass * fix_scale)); + if self.is_lifeform { actor.insert(actor::LifeForm::default()); actor.insert(actor::Suit { @@ -392,8 +404,6 @@ impl ParserState { ..default() }); } - actor.insert(RigidBody::Dynamic); - actor.insert(Collider::cuboid(1.0, 1.0, 1.0)); //info!("Spawning actor {} with model {} at {}/{}/{}", // self.name, self.model, self.pos.x, self.pos.y, self.pos.z); @@ -550,6 +560,33 @@ pub fn load_defs( ["engine", "ion"] => { state.engine_type = actor::EngineType::Ion; } + ["mass", value] => { + if let Ok(value_float) = value.parse::() { + state.mass = value_float; + } + else { + error!("Can't parse float: {line}"); + continue; + } + } + ["collider", "sphere", radius] => { + if let Ok(radius_float) = radius.parse::() { + state.collider = Collider::sphere(radius_float); + } + else { + error!("Can't parse float: {line}"); + continue; + } + } + ["collider", "capsule", height, radius] => { + if let (Ok(height_float), Ok(radius_float)) = (height.parse::(), radius.parse::()) { + state.collider = Collider::capsule(height_float, radius_float); + } + else { + error!("Can't parse float: {line}"); + continue; + } + } // Parsing chats ["chat", chat_name] => {