support keyboard also while gamepad connected

This commit is contained in:
2025-03-16 21:04:20 +01:00
parent 7241f30094
commit 8c7190813a

View File

@@ -170,12 +170,13 @@ fn apply_controls(
return; return;
}; };
let controls = controls let mut direction = player.forward().as_vec3() * -controls.keyboard_state.move_dir.y;
.gamepad_state direction += player.right().as_vec3() * -controls.keyboard_state.move_dir.x;
.unwrap_or_else(|| controls.keyboard_state);
let mut direction = player.forward().as_vec3() * -controls.move_dir.y; if let Some(gamepad) = controls.gamepad_state {
direction += player.right().as_vec3() * -controls.move_dir.x; 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) { if movement.any_direction != (direction != Vec3::ZERO) {
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 // 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. // 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 { controller.action(TnuaBuiltinJump {
// The height is the only mandatory field of the jump button. // The height is the only mandatory field of the jump button.
height: 4.0, height: 4.0,