add "wants novelocity" command to icarus

This commit is contained in:
yuni 2024-04-05 01:19:46 +02:00
parent 83de08034a
commit 5d52d3cdf4
3 changed files with 46 additions and 6 deletions

View file

@ -13,6 +13,7 @@ impl Plugin for ActorPlugin {
app.add_systems(FixedUpdate, (
update_physics_lifeforms,
handle_wants_norotation,
handle_wants_novelocity,
));
app.add_systems(Update, (
handle_input,
@ -62,6 +63,7 @@ impl Default for Actor {
#[derive(Component)] pub struct ActorEnteringVehicle;
#[derive(Component)] pub struct ActorVehicleBeingEntered;
#[derive(Component)] pub struct WantsNoRotation;
#[derive(Component)] pub struct WantsNoVelocity;
#[derive(Component)]
pub struct LifeForm {
@ -299,13 +301,14 @@ fn handle_collisions(
}
fn handle_wants_norotation(
time: Res<Time>,
mut q_v_ang: Query<(&mut AngularVelocity, &Engine), With<WantsNoRotation>>,
//time: Res<Time>,
mut q_angularvelocity: Query<(&mut AngularVelocity, &Engine), With<WantsNoRotation>>,
) {
let d = time.delta_seconds();
for (mut v_ang, engine) in &mut q_v_ang {
let epsilon = 0.0001;
//let d = time.delta_seconds();
for (mut v_ang, engine) in &mut q_angularvelocity {
let total = v_ang.0.length();
if total <= 0.0001 {
if total <= epsilon {
if total > 0.0 {
v_ang.0 = DVec3::splat(0.0);
}
@ -316,3 +319,29 @@ fn handle_wants_norotation(
}
}
}
fn handle_wants_novelocity(
time: Res<Time>,
mut q_velocity: Query<(&mut LinearVelocity, &Engine), With<WantsNoVelocity>>,
) {
let dt = time.delta_seconds();
let epsilon = 0.0001;
for (mut v, engine) in &mut q_velocity {
let total = v.0.length();
if total <= epsilon {
if total > 0.0 {
v.0 = DVec3::splat(0.0);
}
// already not moving
continue;
}
// TODO: respect engine parameters for different thrusts for different directions
let avg_thrust = (engine.thrust_forward + engine.thrust_back + engine.thrust_sideways) / 3.0;
let acceleration = (avg_thrust * dt) as f64 * -v.0;
v.0 += acceleration;
if v.0.length() + epsilon < acceleration.length() {
v.0 = DVec3::splat(0.0);
}
}
}

View file

@ -50,6 +50,7 @@ struct ParserState {
is_vehicle: bool,
has_physics: bool,
wants_norotation: bool,
wants_novelocity: bool,
collider_is_mesh: bool,
thrust_forward: f32,
thrust_sideways: f32,
@ -101,6 +102,7 @@ impl Default for ParserState {
is_vehicle: false,
has_physics: true,
wants_norotation: false,
wants_novelocity: false,
collider_is_mesh: false,
thrust_forward: default_engine.thrust_forward,
thrust_sideways: default_engine.thrust_forward,
@ -427,6 +429,9 @@ pub fn load_defs(
["wants", "norotation"] => {
state.wants_norotation = true;
}
["wants", "novelocity"] => {
state.wants_novelocity = true;
}
// Parsing chats
["chat", chat_name] => {
@ -618,8 +623,13 @@ fn spawn_entities(
});
}
if state.wants_norotation {
// NOTE: requires an engine to slow down rotation
actor.insert(actor::WantsNoRotation);
}
if state.wants_novelocity {
// NOTE: requires an engine to slow down velocity
actor.insert(actor::WantsNoVelocity);
}
if let Some(color) = state.light_color {
actor.insert(PointLightBundle {
point_light: PointLight {

View file

@ -210,8 +210,9 @@ actor 70 -25 -60 suit
mass 200.0
collider capsule 2 1
angularmomentum 0.1 0.2 0.1
thrust 1.2 1 1 3 1.5
thrust 1.2 1 1 10 1.5
wants norotation
wants novelocity
pronoun it
chat hi_icarus
name Icarus