unify rotation stabilizer of players and npcs

This commit is contained in:
yuni 2024-05-22 23:29:54 +02:00
parent 93e5ee26e4
commit 8acbd4f33b
2 changed files with 17 additions and 15 deletions

View file

@ -526,8 +526,9 @@ fn handle_wants_maxrotation(
}
} else {
let angular_slowdown: f64 =
(2.0 - engine.reaction_wheels.powf(0.01).clamp(1.001, 1.1)) as f64;
(2.0 - engine.reaction_wheels.powf(0.05).clamp(1.001, 1.1)) as f64;
v_ang.0 *= angular_slowdown;
//v_ang.0 *= angular_slowdown.clamp(0.97, 1.0);
}
}
}

View file

@ -414,6 +414,7 @@ fn manage_player_actor(
#[allow(clippy::too_many_arguments)]
pub fn apply_input_to_player(
time: Res<Time>,
mut commands: Commands,
settings: Res<var::Settings>,
windows: Query<&Window, With<PrimaryWindow>>,
mut mouse_events: EventReader<MouseMotion>,
@ -422,12 +423,13 @@ pub fn apply_input_to_player(
q_target: Query<&LinearVelocity, (With<hud::IsTargeted>, Without<actor::PlayerCamera>)>,
mut q_playercam: Query<
(
Entity,
&Transform,
&mut actor::Engine,
&mut AngularVelocity,
&mut LinearVelocity,
&mut ExternalTorque,
Option<&actor::PlayerDrivesThis>,
Option<&actor::WantsMaxRotation>,
),
(With<actor::PlayerCamera>, Without<Camera>),
>,
@ -456,7 +458,7 @@ pub fn apply_input_to_player(
DVec3::splat(0.0)
};
if let Ok((player_transform, mut engine, mut angularvelocity, mut v, mut torque, bike)) =
if let Ok((player_entity, player_transform, mut engine, mut v, mut torque, bike, maxrot)) =
q_playercam.get_single_mut()
{
// Handle key input
@ -581,12 +583,6 @@ pub fn apply_input_to_player(
}
}
let slowrot = settings.rotation_stabilizer_active || key_input.pressed(settings.key_stop);
let angular_slowdown: f64 = if slowrot {
(2.0 - engine.reaction_wheels.powf(0.05).clamp(1.001, 1.1)) as f64
} else {
1.0
};
if pitch_yaw_rot.length_squared() > 1.0e-18 {
play_reactionwheel_sound = true;
pitch_yaw_rot *=
@ -595,13 +591,18 @@ pub fn apply_input_to_player(
player_transform.rotation
* Vec3::new(pitch_yaw_rot[0], pitch_yaw_rot[1], pitch_yaw_rot[2]),
));
angularvelocity.0 *= angular_slowdown.clamp(0.97, 1.0) as f64;
} else {
if angularvelocity.length_squared() > 1.0e-18 {
angularvelocity.0 *= angular_slowdown;
} else {
angularvelocity.0 = DVec3::splat(0.0);
}
if settings.rotation_stabilizer_active || key_input.pressed(settings.key_stop) {
if maxrot.is_none() {
commands
.entity(player_entity)
.insert(actor::WantsMaxRotation(0.0));
}
} else if maxrot.is_some() {
commands
.entity(player_entity)
.remove::<actor::WantsMaxRotation>();
}
let mut sinks: HashMap<audio::Sfx, &AudioSink> = HashMap::new();