Skip to content
Snippets Groups Projects
Verified Commit 38eff07f authored by Louis's avatar Louis :fire:
Browse files

Simplify player input

parent 0dfeeabb
No related branches found
No related tags found
No related merge requests found
...@@ -54,28 +54,25 @@ pub fn handle_input( ...@@ -54,28 +54,25 @@ pub fn handle_input(
input: PolyInputManager, input: PolyInputManager,
mut query: Query<(&mut Velocity, &KinematicCharacterControllerOutput), With<Player>>, mut query: Query<(&mut Velocity, &KinematicCharacterControllerOutput), With<Player>>,
) { ) {
let mut delta_x = None;
let mut delta_y = None;
for (mut velocity, controller) in &mut query { for (mut velocity, controller) in &mut query {
if controller.grounded && input.is_jump_just_pressed() { let delta_y = if controller.grounded && input.is_jump_just_pressed() {
delta_y = Some(40.0); Some(40.0)
} } else {
None
};
if input.is_right_pressed_or_active() { let delta_x = if input.is_right_pressed_or_active() {
delta_x = Some(200.0); 200.0
} else if input.is_left_pressed_or_active() { } else if input.is_left_pressed_or_active() {
delta_x = Some(-200.0); -200.0
} else { } else {
delta_x = Some(0.0); 0.0
} };
if let Some(dy) = delta_y { if let Some(dy) = delta_y {
velocity.y = dy; velocity.y = dy;
} }
if let Some(dx) = delta_x { velocity.x = delta_x;
velocity.x = dx;
}
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment