use bevy::prelude::*; use leafwing_input_manager::prelude::*; fn main() { App::new() .add_plugins(DefaultPlugins) // This plugin maps inputs to an input-type agnostic action-state // We need to provide it with an enum which stores the possible actions a player could take .add_plugins(InputManagerPlugin::::default()) // The InputMap and ActionState components will be added to any entity with the Player component .add_systems(Startup, spawn_player) // Read the ActionState in your systems using queries! .add_systems(Update, jump) .run(); } // This is the list of "things in the game I want to be able to do based on input" #[derive(Actionlike, PartialEq, Eq, Clone, Copy, Hash, Debug, Reflect)] enum Action { Run, Jump, } #[derive(Component)] struct Player; fn spawn_player(mut commands: Commands) { // Describes how to convert from player inputs into those actions let input_map = InputMap::new([(Action::Jump, KeyCode::Space)]); commands .spawn(InputManagerBundle::with_map(input_map)) .insert(Player); } // Query for the `ActionState` component in your game logic systems! fn jump(query: Query<&ActionState, With>) { let action_state = query.single(); // Each action has a button-like state of its own that you can check if action_state.just_pressed(&Action::Jump) { println!("I'm jumping!"); } }