From cbd7c4481ca6f6ce10f3469d99eb5058b6ceec1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20B=C3=B6klin?= Date: Thu, 5 Aug 2021 08:34:21 +0200 Subject: [PATCH] Make character upright itself even while idle --- common/src/states/utils.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/common/src/states/utils.rs b/common/src/states/utils.rs index 3e0553982a..e3d8c2ca2d 100644 --- a/common/src/states/utils.rs +++ b/common/src/states/utils.rs @@ -349,18 +349,17 @@ pub fn handle_forced_movement( } pub fn handle_orientation(data: &JoinData<'_>, update: &mut StateUpdate, efficiency: f32) { - if let Some(dir) = (is_strafing(data, update) || update.character.is_attack()) + let dir = (is_strafing(data, update) || update.character.is_attack()) .then(|| data.inputs.look_dir.to_horizontal().unwrap_or_default()) .or_else(|| Dir::from_unnormalized(data.inputs.move_dir.into())) - { - let rate = { - let angle = update.ori.look_dir().angle_between(*dir); - data.body.base_ori_rate() * efficiency * std::f32::consts::PI / angle - }; - update.ori = update - .ori - .slerped_towards(dir.into(), (data.dt.0 * rate).min(1.0)); + .unwrap_or_else(|| data.ori.to_horizontal().look_dir()); + let rate = { + let angle = update.ori.look_dir().angle_between(*dir); + data.body.base_ori_rate() * efficiency * std::f32::consts::PI / angle }; + update.ori = update + .ori + .slerped_towards(dir.into(), (data.dt.0 * rate).min(1.0)); } /// Updates components to move player as if theyre swimming