add velocity command

This commit is contained in:
yuni 2024-04-05 01:55:40 +02:00
parent e29a8abebf
commit 93cc607613

View file

@ -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::<f64>(), y.parse::<f64>(), z.parse::<f64>()) {
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::<f64>(), y.parse::<f64>(), z.parse::<f64>()) {
@ -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 {