2022-05-16 13:53:20 +00:00
|
|
|
//! Shows handling of gamepad input, connections, and disconnections.
|
|
|
|
|
2024-04-01 19:59:08 +00:00
|
|
|
use bevy::prelude::*;
|
2020-09-18 21:43:47 +00:00
|
|
|
|
|
|
|
fn main() {
|
2021-07-27 20:21:06 +00:00
|
|
|
App::new()
|
2020-11-03 03:01:17 +00:00
|
|
|
.add_plugins(DefaultPlugins)
|
2023-03-18 01:45:34 +00:00
|
|
|
.add_systems(Update, gamepad_system)
|
2020-09-18 21:43:47 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2020-10-21 17:27:00 +00:00
|
|
|
fn gamepad_system(
|
2021-12-08 20:28:08 +00:00
|
|
|
gamepads: Res<Gamepads>,
|
2023-12-06 20:32:34 +00:00
|
|
|
button_inputs: Res<ButtonInput<GamepadButton>>,
|
2020-10-15 19:45:34 +00:00
|
|
|
button_axes: Res<Axis<GamepadButton>>,
|
2020-10-21 17:27:00 +00:00
|
|
|
axes: Res<Axis<GamepadAxis>>,
|
2020-10-15 19:45:34 +00:00
|
|
|
) {
|
2022-09-03 20:08:54 +00:00
|
|
|
for gamepad in gamepads.iter() {
|
2022-05-02 13:20:55 +00:00
|
|
|
if button_inputs.just_pressed(GamepadButton::new(gamepad, GamepadButtonType::South)) {
|
2021-04-22 23:30:48 +00:00
|
|
|
info!("{:?} just pressed South", gamepad);
|
2022-05-02 13:20:55 +00:00
|
|
|
} else if button_inputs.just_released(GamepadButton::new(gamepad, GamepadButtonType::South))
|
|
|
|
{
|
2021-04-22 23:30:48 +00:00
|
|
|
info!("{:?} just released South", gamepad);
|
2020-09-18 21:43:47 +00:00
|
|
|
}
|
|
|
|
|
2020-10-21 22:56:07 +00:00
|
|
|
let right_trigger = button_axes
|
2022-05-02 13:20:55 +00:00
|
|
|
.get(GamepadButton::new(
|
|
|
|
gamepad,
|
|
|
|
GamepadButtonType::RightTrigger2,
|
|
|
|
))
|
2020-10-21 22:56:07 +00:00
|
|
|
.unwrap();
|
|
|
|
if right_trigger.abs() > 0.01 {
|
2021-04-22 23:30:48 +00:00
|
|
|
info!("{:?} RightTrigger2 value is {}", gamepad, right_trigger);
|
2020-10-21 22:56:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let left_stick_x = axes
|
2022-05-02 13:20:55 +00:00
|
|
|
.get(GamepadAxis::new(gamepad, GamepadAxisType::LeftStickX))
|
2020-10-21 22:56:07 +00:00
|
|
|
.unwrap();
|
|
|
|
if left_stick_x.abs() > 0.01 {
|
2021-04-22 23:30:48 +00:00
|
|
|
info!("{:?} LeftStickX value is {}", gamepad, left_stick_x);
|
2020-10-21 22:56:07 +00:00
|
|
|
}
|
2020-09-18 21:43:47 +00:00
|
|
|
}
|
|
|
|
}
|