Add configuration factors for forward/back/strafe motion.

This commit is contained in:
Nolan Darilek 2021-05-30 14:35:10 -05:00
parent d5c580f165
commit 33921acee8

View File

@ -145,6 +145,14 @@ fn movement_controls<S, A: 'static>(
}
if direction.length_squared() != 0. {
direction = direction.normalize();
if direction.x > 0. {
direction.x *= config.forward_movement_factor;
} else if direction.x < 0. {
direction.x *= config.backward_movement_factor;
}
if direction.y != 0. {
direction.y *= config.strafe_movement_factor;
}
let strength = if let (Some(forward), Some(backward), Some(left), Some(right)) = (
config.action_forward.clone(),
config.action_backward.clone(),
@ -168,7 +176,7 @@ fn movement_controls<S, A: 'static>(
let s = if sprinting {
**max_speed
} else {
**max_speed / 3.
**max_speed / config.sprint_movement_factor
};
speed.0 = s;
direction *= s;
@ -438,6 +446,10 @@ pub struct NavigationConfig<S, A> {
pub action_rotate_left: Option<A>,
pub action_rotate_right: Option<A>,
pub action_sprint: Option<A>,
pub forward_movement_factor: f32,
pub backward_movement_factor: f32,
pub strafe_movement_factor: f32,
pub sprint_movement_factor: f32,
pub movement_states: Vec<S>,
pub movement_control_states: Vec<S>,
}
@ -452,6 +464,10 @@ impl<S, A> Default for NavigationConfig<S, A> {
action_rotate_left: None,
action_rotate_right: None,
action_sprint: None,
forward_movement_factor: 1.,
backward_movement_factor: 1.,
strafe_movement_factor: 1.,
sprint_movement_factor: 3.,
movement_states: vec![],
movement_control_states: vec![],
}