https://github.com/bevious/bevy_actify
An input action plugin for Bevy
https://github.com/bevious/bevy_actify
bevy bevy-plugin input input-handling
Last synced: 9 months ago
JSON representation
An input action plugin for Bevy
- Host: GitHub
- URL: https://github.com/bevious/bevy_actify
- Owner: bevious
- License: apache-2.0
- Created: 2025-03-25T07:50:13.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-04-02T06:11:55.000Z (9 months ago)
- Last Synced: 2025-04-02T07:23:31.850Z (9 months ago)
- Topics: bevy, bevy-plugin, input, input-handling
- Language: Rust
- Homepage: https://crates.io/crates/bevy_actify
- Size: 66.4 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE-2.0
Awesome Lists containing this project
README
An input action plugin for Bevy
A tiny abstraction layer for input handling in [Bevy](https://bevyengine.org/) that decouples
input sources from game logic through clean action-based interfaces.
## Problem
Raw input handling leads to:
- Tight coupling between devices and game logic
- Code duplication across input methods
- Messy state management
## How to use
### Basics
#### InputActionDrain
`InputActionDrain` is a system parameter, that is the *vassel* into which the systems *pour* input action state.
For example a system would read keyboard input and *pour* the state into the appropriate
`InputActionDrain`.
#### InputActionState
`InputActionState` is a system parameter, that is the source of current input action state. The gameplay system
(i.e. movement, jump) would read the input action state from this.
#### InputActionReader
`InputActionReader` is a system parameter, that provides an event based interface, similar to `EventReader` (actually it
uses an event reader under the hood). The read values are of type `InputActionStatus`—an `InputActionStatus` can be one of:
- `Started` when the input action has just started to be active,
- `Updated` when the input action has already been active, but the value has changed,
- `Stopped` when the input action had been active, but now is not.
### Run conditions
This library provides several input action based system run conditions. Those are:
- `input_action_active`: The system will run each frame the input action is active
- `input_action_started`: Similar to `ButtonInput`'s `just_pressed`—will make your system run at the frame on which the action has started
- `input_action_updated`: The system will run if the state of an input action has changed (i.e. an axis changed direction)
- `input_action_stopped`: The system will run once the input action gets stopped (i.e. a button has been released)
### Example
```rust
use bevy::{prelude::*, input::InputSystem};
use bevy_actify::prelude::*;
// 1. Define your action
#[derive(InputAction, Clone, PartialEq)]
struct Jump(f32); // f32 for analog sensetivity
// 2. Map inputs to actions
fn keyboard_input(keyboard: Res>, mut action: InputActionDrain) {
if keyboard.pressed(KeyCode::Space) {
action.pour(Jump(1f32));
}
}
// 3. Use in game systems
fn character_jump(action: InputActionState) {
if let Some(state) = action.state() {
let jump_power = state.0;
// Apply force...
}
}
// 4. Register the input action and systems
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_input_action::()
.add_systems(PreUpdate, keyboard_input.after(InputSystem).before(InputActionSystem)) // properly order your systems to avoid 1 frame delay!
.add_systems(Update, character_jump)
.run();
}
```
## How to contribute
Fork repository, make changes, and send us a pull request.
We will review your changes and apply them to the main
branch shortly, provided they don't violate our quality standards.
## License
This project is dual-licensed under:
- [MIT License](LICENSE-MIT)
- [Apache 2.0 License](LICENSE-APACHE-2.0)
You may choose either license at your option.