add "wants norotation" command to satellite and icarus

This commit is contained in:
yuni 2024-04-05 00:54:58 +02:00
parent beb241e9d6
commit 83de08034a
3 changed files with 34 additions and 0 deletions

View file

@ -1,5 +1,6 @@
use bevy::prelude::*; use bevy::prelude::*;
use bevy_xpbd_3d::prelude::*; use bevy_xpbd_3d::prelude::*;
use bevy::math::DVec3;
use crate::{actor, audio, chat, nature, settings}; use crate::{actor, audio, chat, nature, settings};
pub const ENGINE_SPEED_FACTOR: f32 = 30.0; pub const ENGINE_SPEED_FACTOR: f32 = 30.0;
@ -11,6 +12,7 @@ impl Plugin for ActorPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_systems(FixedUpdate, ( app.add_systems(FixedUpdate, (
update_physics_lifeforms, update_physics_lifeforms,
handle_wants_norotation,
)); ));
app.add_systems(Update, ( app.add_systems(Update, (
handle_input, handle_input,
@ -59,6 +61,7 @@ impl Default for Actor {
#[derive(Component)] pub struct InConversationWithPlayer; #[derive(Component)] pub struct InConversationWithPlayer;
#[derive(Component)] pub struct ActorEnteringVehicle; #[derive(Component)] pub struct ActorEnteringVehicle;
#[derive(Component)] pub struct ActorVehicleBeingEntered; #[derive(Component)] pub struct ActorVehicleBeingEntered;
#[derive(Component)] pub struct WantsNoRotation;
#[derive(Component)] #[derive(Component)]
pub struct LifeForm { pub struct LifeForm {
@ -294,3 +297,22 @@ fn handle_collisions(
} }
} }
} }
fn handle_wants_norotation(
time: Res<Time>,
mut q_v_ang: Query<(&mut AngularVelocity, &Engine), With<WantsNoRotation>>,
) {
let d = time.delta_seconds();
for (mut v_ang, engine) in &mut q_v_ang {
let total = v_ang.0.length();
if total <= 0.0001 {
if total > 0.0 {
v_ang.0 = DVec3::splat(0.0);
}
}
else {
let angular_slowdown: f64 = (2.0 - engine.reaction_wheels.powf(0.01).clamp(1.001, 1.1)) as f64;
v_ang.0 *= angular_slowdown;
}
}
}

View file

@ -49,6 +49,7 @@ struct ParserState {
is_suited: bool, is_suited: bool,
is_vehicle: bool, is_vehicle: bool,
has_physics: bool, has_physics: bool,
wants_norotation: bool,
collider_is_mesh: bool, collider_is_mesh: bool,
thrust_forward: f32, thrust_forward: f32,
thrust_sideways: f32, thrust_sideways: f32,
@ -99,6 +100,7 @@ impl Default for ParserState {
is_suited: false, is_suited: false,
is_vehicle: false, is_vehicle: false,
has_physics: true, has_physics: true,
wants_norotation: false,
collider_is_mesh: false, collider_is_mesh: false,
thrust_forward: default_engine.thrust_forward, thrust_forward: default_engine.thrust_forward,
thrust_sideways: default_engine.thrust_forward, thrust_sideways: default_engine.thrust_forward,
@ -422,6 +424,9 @@ pub fn load_defs(
continue; continue;
} }
} }
["wants", "norotation"] => {
state.wants_norotation = true;
}
// Parsing chats // Parsing chats
["chat", chat_name] => { ["chat", chat_name] => {
@ -612,6 +617,9 @@ fn spawn_entities(
..default() ..default()
}); });
} }
if state.wants_norotation {
actor.insert(actor::WantsNoRotation);
}
if let Some(color) = state.light_color { if let Some(color) = state.light_color {
actor.insert(PointLightBundle { actor.insert(PointLightBundle {
point_light: PointLight { point_light: PointLight {

View file

@ -90,6 +90,8 @@ actor 3000 0 0 moonlet
actor -200 -110 1000 satellite actor -200 -110 1000 satellite
relativeto player relativeto player
scale 40 scale 40
wants norotation
thrust 0 0 0 300 1
collider capsule 7.5 1 collider capsule 7.5 1
rotationy 0.5 rotationy 0.5
angularmomentum 0 0 0 angularmomentum 0 0 0
@ -208,6 +210,8 @@ actor 70 -25 -60 suit
mass 200.0 mass 200.0
collider capsule 2 1 collider capsule 2 1
angularmomentum 0.1 0.2 0.1 angularmomentum 0.1 0.2 0.1
thrust 1.2 1 1 3 1.5
wants norotation
pronoun it pronoun it
chat hi_icarus chat hi_icarus
name Icarus name Icarus