support keyboard also while gamepad connected
This commit is contained in:
@@ -170,12 +170,13 @@ fn apply_controls(
|
||||
return;
|
||||
};
|
||||
|
||||
let controls = controls
|
||||
.gamepad_state
|
||||
.unwrap_or_else(|| controls.keyboard_state);
|
||||
let mut direction = player.forward().as_vec3() * -controls.keyboard_state.move_dir.y;
|
||||
direction += player.right().as_vec3() * -controls.keyboard_state.move_dir.x;
|
||||
|
||||
let mut direction = player.forward().as_vec3() * -controls.move_dir.y;
|
||||
direction += player.right().as_vec3() * -controls.move_dir.x;
|
||||
if let Some(gamepad) = controls.gamepad_state {
|
||||
direction += player.forward().as_vec3() * -gamepad.move_dir.y;
|
||||
direction += player.right().as_vec3() * -gamepad.move_dir.x;
|
||||
}
|
||||
|
||||
if movement.any_direction != (direction != Vec3::ZERO) {
|
||||
movement.any_direction = direction != Vec3::ZERO;
|
||||
@@ -196,7 +197,7 @@ fn apply_controls(
|
||||
|
||||
// Feed the jump action every frame as long as the player holds the jump button. If the player
|
||||
// stops holding the jump button, simply stop feeding the action.
|
||||
if controls.jump {
|
||||
if controls.keyboard_state.jump || controls.gamepad_state.map(|gp| gp.jump).unwrap_or(false) {
|
||||
controller.action(TnuaBuiltinJump {
|
||||
// The height is the only mandatory field of the jump button.
|
||||
height: 4.0,
|
||||
|
||||
Reference in New Issue
Block a user