From cab5c8eaf52fd092fb5a4801e216ad5797c43f4e Mon Sep 17 00:00:00 2001 From: hut Date: Sat, 30 Mar 2024 23:13:22 +0100 Subject: [PATCH] fix angularmomentum command --- src/actor.rs | 4 ---- src/defs.txt | 4 +++- src/world.rs | 11 ++++++----- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/actor.rs b/src/actor.rs index 4240846..61a3d07 100644 --- a/src/actor.rs +++ b/src/actor.rs @@ -62,8 +62,6 @@ pub struct Actor { pub id: String, pub hp: f32, pub m: f32, // mass - pub v: Vec3, // velocity - pub angular_momentum: Quat, pub inside_entity: u32, pub camdistance: f32, } @@ -74,9 +72,7 @@ impl Default for Actor { id: "".to_string(), hp: 100.0, m: 100.0, - v: Vec3::ZERO, inside_entity: NO_RIDE, - angular_momentum: Quat::from_euler(EulerRot::XYZ, 0.001, 0.01, 0.003), camdistance: 15.0, } } diff --git a/src/defs.txt b/src/defs.txt index dd710fe..663429d 100644 --- a/src/defs.txt +++ b/src/defs.txt @@ -4,6 +4,7 @@ actor 0 0 0 suit scale 1 oxygen 0.008 health 0.3 + angularmomentum 0 0 0 collider capsule 2 1 thrust 1.2 1 1 1 1.5 engine monopropellant @@ -17,7 +18,7 @@ actor 300000 0 500000 jupiter actor 3000 0 0 moonlet scale 500 mass 10000000 - angularmomentum 0 0.0001 0 + angularmomentum 0 0.15 0 actor 1000 20 300 monolith scale 2 @@ -108,6 +109,7 @@ actor 10 -30 20 MeteorAceGT collider sphere 1.5 camdistance 50 mass 3000 + angularmomentum 0.1 0.1 0.3 actor 10 0 70 suit name Icarus diff --git a/src/world.rs b/src/world.rs index 5c65b7a..de2b716 100644 --- a/src/world.rs +++ b/src/world.rs @@ -97,7 +97,7 @@ pub fn setup( commands.spawn(( actor::Actor::default(), RigidBody::Dynamic, - AngularVelocity(Vec3::new(0.001, 0.001, 0.0003)), + AngularVelocity(Vec3::new(0.1, 0.1, 0.03)), LinearVelocity(Vec3::new(0.0, 0.0, 0.35)), Collider::sphere(1.0), SceneBundle { @@ -202,7 +202,7 @@ struct ParserState { model: String, model_scale: f32, rotation: Quat, - angular_momentum: Quat, + angular_momentum: Vec3, pronoun: String, is_player: bool, is_lifeform: bool, @@ -248,7 +248,7 @@ impl Default for ParserState { model: "".to_string(), model_scale: 1.0, rotation: Quat::IDENTITY, - angular_momentum: default_actor.angular_momentum, + angular_momentum: Vec3::new(0.03, 0.3, 0.09), pronoun: "they/them".to_string(), is_player: false, is_lifeform: false, @@ -325,7 +325,6 @@ impl ParserState { fn spawn_actor(&mut self, commands: &mut Commands, asset_server: &Res) { let mut actor = commands.spawn_empty(); actor.insert(actor::Actor { - angular_momentum: self.angular_momentum, id: self.id.clone(), camdistance: self.camdistance, ..default() @@ -344,9 +343,11 @@ impl ParserState { if self.has_physics { let fix_scale = 1.0 / self.model_scale.powf(3.0); actor.insert(RigidBody::Dynamic); + actor.insert(AngularVelocity(self.angular_momentum)); actor.insert(self.collider.clone()); actor.insert(ColliderDensity(self.mass * fix_scale)); } + // TODO: angular velocity for objects without collisions, static objects // Optional Components if self.is_player { @@ -516,7 +517,7 @@ pub fn load_defs( ["angularmomentum", x, y, z] => { if let (Ok(x_float), Ok(y_float), Ok(z_float)) = (x.parse::(), y.parse::(), z.parse::()) { - state.angular_momentum = Quat::from_euler(EulerRot::XYZ, x_float, y_float, z_float); + state.angular_momentum = Vec3::new(x_float, y_float, z_float); } else { error!("Can't parse float: {line}");