Gamepad

Gamepad

  • vendor_id : core::option::Option
  • product_id : core::option::Option
  • digital : bevy_input::button_input::ButtonInput<bevy_input::gamepad::GamepadButton>
  • analog : bevy_input::axis::Axis<bevy_input::gamepad::GamepadInput>

Description

Stores a connected gamepad's metadata such as the name and its [GamepadButton] and [GamepadAxis].

An entity with this component is spawned automatically after [GamepadConnectionEvent] and updated by [gamepad_event_processing_system].

See also [GamepadSettings] for configuration.

Examples

# use bevy_input::gamepad::{Gamepad, GamepadAxis, GamepadButton};
# use bevy_ecs::system::Query;
# use bevy_core::Name;
#
fn gamepad_usage_system(gamepads: Query<(&Name, &Gamepad)>) {
    for (name, gamepad) in &gamepads {
        println!("{name}");

        if gamepad.just_pressed(GamepadButton::North) {
            println!("{} just pressed North", name)
        }

        if let Some(left_stick_x) = gamepad.get(GamepadAxis::LeftStickX)  {
            println!("left stick X: {}", left_stick_x)
        }
    }
}

Functions