From 61233fd59d8d43aa78465d47b84f02e3e38b6da4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20B=C3=B6klin?= Date: Fri, 4 Jun 2021 16:56:22 +0200 Subject: [PATCH] Don't reset ori when exiting glide state and misc tweaks --- common/src/states/glide.rs | 38 ++++++++++---------------------- common/src/states/glide_wield.rs | 8 ++++--- common/systems/src/phys.rs | 2 +- 3 files changed, 18 insertions(+), 30 deletions(-) diff --git a/common/src/states/glide.rs b/common/src/states/glide.rs index 80007b09e1..e4e96361f2 100644 --- a/common/src/states/glide.rs +++ b/common/src/states/glide.rs @@ -16,15 +16,13 @@ const MAX_LIFT_DRAG_RATIO_AOA: f32 = PI * 0.04; #[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct Data { pub glider: Glider, - last_ori: Ori, timer: f32, inputs_disabled: bool, } impl Data { - pub fn new(glider: Glider, ori: &Ori) -> Self { + pub fn new(glider: Glider) -> Self { Self { - last_ori: *ori, timer: 0.0, inputs_disabled: true, glider, @@ -109,21 +107,18 @@ impl CharacterBehavior for Data { && (data.vel.0 - data.physics.ground_vel).magnitude_squared() < 2_f32.powi(2) { update.character = CharacterState::GlideWield(glide_wield::Data(self.glider)); - update.ori = update.ori.to_horizontal(); } else if data.physics.in_liquid().is_some() || data.inventory.equipped(EquipSlot::Glider).is_none() { update.character = CharacterState::Idle; - update.ori = update.ori.to_horizontal(); } else if !handle_climb(&data, &mut update) { // Tweaks - let def_pitch = MAX_LIFT_DRAG_RATIO_AOA * tweak!(2.0); - let max_pitch = tweak!(0.2) * PI; - let max_roll = tweak!(0.30) * PI; - let inputs_rate = tweak!(4.0); + let def_pitch = MAX_LIFT_DRAG_RATIO_AOA * tweak!(1.0); + let max_pitch = tweak!(0.3) * PI; + let max_roll = tweak!(0.2) * PI; + let inputs_rate = tweak!(5.0); let look_pitch_rate = tweak!(5.0); let autoroll_rate = tweak!(5.0); - let rot_with_char = tweak!(false); let yaw_correction_rate = tweak!(1.0); let char_yaw_follow_rate = tweak!(2.0); // ---- @@ -138,21 +133,16 @@ impl CharacterBehavior for Data { let char_up = data.ori.up(); + let ori = self.glider.ori; let mut glider = self.glider; - if rot_with_char { - glider.ori = glider - .ori - .prerotated(self.last_ori.up().rotation_between(char_up)); - } - { - let glider_up = glider.ori.up(); - let d = glider_up.dot(*char_up); + let glider_up = ori.up(); + let up_dot = glider_up.dot(*char_up); if let Some(roll_input) = self.roll_input(data.inputs) { - if (d - max_roll.cos()).is_sign_positive() - || (glider.ori.right().dot(*char_up).is_sign_positive() + if (up_dot - max_roll.cos()).is_sign_positive() + || (ori.right().dot(*char_up).is_sign_positive() == roll_input.is_sign_positive()) { glider.roll(data.dt.0 * inputs_rate * roll_input * max_roll); @@ -165,8 +155,8 @@ impl CharacterBehavior for Data { } if let Some(pitch_input) = self.pitch_input(data.inputs) { - if (d - max_pitch.cos()).is_sign_positive() - || (glider.ori.look_dir().dot(*char_up).is_sign_negative() + if (up_dot - max_pitch.cos()).is_sign_positive() + || (ori.look_dir().dot(*char_up).is_sign_negative() == pitch_input.is_sign_positive()) { glider.pitch(data.dt.0 * inputs_rate * pitch_input * max_pitch); @@ -182,13 +172,10 @@ impl CharacterBehavior for Data { ); update.character = CharacterState::Glide(Self { - last_ori: update.ori, timer: self.timer + data.dt.0, inputs_disabled: self.inputs_disabled && !data.inputs.move_dir.is_approx_zero(), glider, }); - } else { - update.ori = update.ori.to_horizontal(); } update @@ -197,7 +184,6 @@ impl CharacterBehavior for Data { fn unwield(&self, data: &JoinData) -> StateUpdate { let mut update = StateUpdate::from(data); update.character = CharacterState::Idle; - update.ori = update.ori.to_horizontal(); update } } diff --git a/common/src/states/glide_wield.rs b/common/src/states/glide_wield.rs index 27bbb435cf..c139dd385d 100644 --- a/common/src/states/glide_wield.rs +++ b/common/src/states/glide_wield.rs @@ -34,13 +34,15 @@ impl CharacterBehavior for Data { let mut glider = self.0; glider.ori = glider.ori.slerped_towards( - Ori::from(data.inputs.look_dir).pitched_up(inline_tweak::tweak!(0.35)), - inline_tweak::tweak!(10.0) * data.dt.0, + Ori::from(data.inputs.look_dir) + .yawed_towards(data.ori.look_dir()) + .pitched_up(inline_tweak::tweak!(0.7)), + inline_tweak::tweak!(3.0) * data.dt.0, ); // If not on the ground while wielding glider enter gliding state update.character = if !data.physics.on_ground { - CharacterState::Glide(glide::Data::new(glider, data.ori)) + CharacterState::Glide(glide::Data::new(glider)) } else if data .physics .in_liquid() diff --git a/common/systems/src/phys.rs b/common/systems/src/phys.rs index afb193f75a..48f687ab38 100644 --- a/common/systems/src/phys.rs +++ b/common/systems/src/phys.rs @@ -62,7 +62,7 @@ fn integrate_glider_forces( { let glider_dir = ori.up(); - let glider_dist = tweak!(2.5); + let glider_dist = tweak!(1.0); let glider_pos = *glider_dir * glider_dist; if let Some(rot) = Dir::from_unnormalized(glider_pos + dv_) .map(|u| {