From 8eb5e0971f697773964ad52128ee8f4fb9956c52 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Wed, 11 Jan 2023 11:38:06 -0600 Subject: [PATCH] Artificually implement some deadzones. --- src/navigation.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/navigation.rs b/src/navigation.rs index 19eed8f..9bb7e80 100644 --- a/src/navigation.rs +++ b/src/navigation.rs @@ -81,10 +81,16 @@ fn movement_controls( if actions.pressed(NavigationAction::Move) { if let Some(pair) = actions.clamped_axis_pair(NavigationAction::Move) { cleanup = true; - let direction = pair.xy(); - let forward_backward_movement_factor = if direction.x > 0. { + let mut direction = pair.xy(); + if direction.x.abs() < 0.5 { + direction.x = 0.; + } + if direction.y.abs() < 0.5 { + direction.y = 0.; + } + let forward_backward_movement_factor = if direction.y > 0. { config.forward_movement_factor - } else if direction.x < 0. { + } else if direction.y < 0. { config.backward_movement_factor } else { 0. @@ -93,7 +99,7 @@ fn movement_controls( config .strafe_movement_factor .min(forward_backward_movement_factor) - } else if direction.y != 0. { + } else if direction.x != 0. { config.strafe_movement_factor } else { forward_backward_movement_factor @@ -102,6 +108,7 @@ fn movement_controls( s *= movement_factor; **speed = s; let mut v = direction * **speed; + v = Vec2::new(v.y, -v.x); v = transform .compute_matrix() .transform_vector3(v.extend(0.)) @@ -132,7 +139,7 @@ fn movement_controls( if actions.pressed(NavigationAction::Rotate) { cleanup = true; let delta = - rotation_speed.radians() * actions.clamped_value(NavigationAction::Rotate); + -rotation_speed.radians() * actions.clamped_value(NavigationAction::Rotate); actions.press(NavigationAction::SetAngularVelocity); actions .action_data_mut(NavigationAction::SetAngularVelocity)