implement collider/mass commands

This commit is contained in:
yuni 2024-03-29 18:20:12 +01:00
parent 349e38e848
commit bb73b1ed1d
2 changed files with 46 additions and 2 deletions

View file

@ -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

View file

@ -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::<f32>() {
state.mass = value_float;
}
else {
error!("Can't parse float: {line}");
continue;
}
}
["collider", "sphere", radius] => {
if let Ok(radius_float) = radius.parse::<f32>() {
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::<f32>(), radius.parse::<f32>()) {
state.collider = Collider::capsule(height_float, radius_float);
}
else {
error!("Can't parse float: {line}");
continue;
}
}
// Parsing chats
["chat", chat_name] => {