Skip to content

Commit

Permalink
0.11 Section: Gamepad Rumble Support
Browse files Browse the repository at this point in the history
  • Loading branch information
nicopap committed Jul 2, 2023
1 parent 84cab00 commit a60338b
Showing 1 changed file with 36 additions and 7 deletions.
43 changes: 36 additions & 7 deletions content/news/2023-07-07-bevy-0.11/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,42 @@ Since our last release a few months ago we've added a _ton_ of new features, bug

<!-- more -->

* **Feature**: description

## Feature

<div class="release-feature-authors">authors: @todo</div>

Description
* **Gamepad Rumble API**: an ECS-friendly way of making controllers rumble

## Gamepad Rumble API

<div class="release-feature-authors">authors: @johanhelsing, @nicopap</div>

You can now use the `EventWriter<GamepadRumbleRequest>` system parameter to
trigger controllers force-feedback motors.

[`gilrs`], the crate bevy uses for gamepad support, allows controlling
force-feedback motors. Sadly, there were no easy way of accessing the
force-feedback API in bevy without tedious bookkeeping.

Now bevy has the `GamepadRumbleRequest` event to do just that.

```rust
fn rumble_system(
gamepads: Res<Gamepads>,
mut rumble_requests: EventWriter<GamepadRumbleRequest>,
) {
for gamepad in gamepads.iter() {
rumble_requests.send(GamepadRumbleRequest::Add {
gamepad,
duration: Duration::from_secs(5),
intensity: GamepadRumbleIntensity::MAX,
});
}
}
```

The `GamepadRumbleRequest::Add` event triggers a force-feedback motor,
controlling how long the vibration should last, the motor to activate,
and the vibration strength. `GamepadRumbleRequest::Stop` immediately stops all
motors.

[`gilrs`]: https://crates.io/crates/gilrs

## <a name="what-s-next"></a>What's Next?

Expand Down

0 comments on commit a60338b

Please sign in to comment.