From 93cc607613e530177f6c9a97d0ea3db90f1cb653 Mon Sep 17 00:00:00 2001 From: hut Date: Fri, 5 Apr 2024 01:55:40 +0200 Subject: [PATCH] add velocity command --- src/commands.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/commands.rs b/src/commands.rs index db11dd9..7a0ce51 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -40,6 +40,7 @@ struct ParserState { model: String, model_scale: f32, rotation: Quat, + velocity: DVec3, angular_momentum: DVec3, pronoun: String, is_sphere: bool, @@ -92,6 +93,7 @@ impl Default for ParserState { model: "".to_string(), model_scale: 1.0, rotation: Quat::IDENTITY, + velocity: DVec3::splat(0.0), angular_momentum: DVec3::new(0.03, 0.3, 0.09), pronoun: "they/them".to_string(), is_sphere: false, @@ -327,6 +329,16 @@ pub fn load_defs( continue; } } + ["velocity", x, y, z] => { + if let (Ok(x_float), Ok(y_float), Ok(z_float)) = + (x.parse::(), y.parse::(), z.parse::()) { + state.velocity = DVec3::new(x_float, y_float, z_float); + } + else { + error!("Can't parse float: {line}"); + continue; + } + } ["angularmomentum", x, y, z] => { if let (Ok(x_float), Ok(y_float), Ok(z_float)) = (x.parse::(), y.parse::(), z.parse::()) { @@ -604,6 +616,7 @@ fn spawn_entities( if state.has_physics { let fix_scale: f64 = 1.0 / (state.model_scale as f64).powf(3.0); actor.insert(RigidBody::Dynamic); + actor.insert(LinearVelocity(state.velocity)); actor.insert(AngularVelocity(state.angular_momentum)); actor.insert(ColliderDensity((state.mass * fix_scale) as f64)); if state.collider_is_mesh {