mirror of
https://github.com/bevyengine/bevy
synced 2024-11-23 13:13:49 +00:00
01e2141ce3
# Objective Fixes #3245 ## Solution - Move GamepadLobby to lib - Add connection_system to InputPlugin - Updated gamepad_input example Co-authored-by: CrazyRoka <rokarostuk@gmail.com> Co-authored-by: Carter Anderson <mcanders1@gmail.com>
37 lines
1.2 KiB
Rust
37 lines
1.2 KiB
Rust
use bevy::{input::gamepad::GamepadButton, prelude::*};
|
|
|
|
fn main() {
|
|
App::new()
|
|
.add_plugins(DefaultPlugins)
|
|
.add_system(gamepad_system)
|
|
.run();
|
|
}
|
|
|
|
fn gamepad_system(
|
|
gamepads: Res<Gamepads>,
|
|
button_inputs: Res<Input<GamepadButton>>,
|
|
button_axes: Res<Axis<GamepadButton>>,
|
|
axes: Res<Axis<GamepadAxis>>,
|
|
) {
|
|
for gamepad in gamepads.iter().cloned() {
|
|
if button_inputs.just_pressed(GamepadButton(gamepad, GamepadButtonType::South)) {
|
|
info!("{:?} just pressed South", gamepad);
|
|
} else if button_inputs.just_released(GamepadButton(gamepad, GamepadButtonType::South)) {
|
|
info!("{:?} just released South", gamepad);
|
|
}
|
|
|
|
let right_trigger = button_axes
|
|
.get(GamepadButton(gamepad, GamepadButtonType::RightTrigger2))
|
|
.unwrap();
|
|
if right_trigger.abs() > 0.01 {
|
|
info!("{:?} RightTrigger2 value is {}", gamepad, right_trigger);
|
|
}
|
|
|
|
let left_stick_x = axes
|
|
.get(GamepadAxis(gamepad, GamepadAxisType::LeftStickX))
|
|
.unwrap();
|
|
if left_stick_x.abs() > 0.01 {
|
|
info!("{:?} LeftStickX value is {}", gamepad, left_stick_x);
|
|
}
|
|
}
|
|
}
|