Skip to content

Commit b5af745

Browse files
nicopapcart
andauthored
0.11 Section: Gamepad Rumble Support (#666)
Co-authored-by: Carter Anderson <mcanders1@gmail.com>
1 parent b6a5ab7 commit b5af745

File tree

1 file changed

+35
-0
lines changed
  • content/news/2023-07-07-bevy-0.11

1 file changed

+35
-0
lines changed

content/news/2023-07-07-bevy-0.11/index.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,41 @@ Since our last release a few months ago we've added a _ton_ of new features, bug
1818
* **Morph targets**: Vertex-based animations
1919
* **Parallax mapping**: Materials now support an optional depth map, giving
2020
flat surfaces a feel of depth through parallaxing the material's textures.
21+
* **Gamepad Rumble API**: an ECS-friendly way of making controllers rumble
22+
23+
## Gamepad Rumble API
24+
25+
<div class="release-feature-authors">authors: @johanhelsing, @nicopap</div>
26+
27+
You can now use the `EventWriter<GamepadRumbleRequest>` system parameter to
28+
trigger controllers force-feedback motors.
29+
30+
[`gilrs`], the crate Bevy uses for gamepad support, allows controlling
31+
force-feedback motors. Sadly, there were no easy way of accessing the
32+
force-feedback API in Bevy without tedious bookkeeping.
33+
34+
Now Bevy has the `GamepadRumbleRequest` event to do just that.
35+
36+
```rust
37+
fn rumble_system(
38+
gamepads: Res<Gamepads>,
39+
mut rumble_requests: EventWriter<GamepadRumbleRequest>,
40+
) {
41+
for gamepad in gamepads.iter() {
42+
rumble_requests.send(GamepadRumbleRequest::Add {
43+
gamepad,
44+
duration: Duration::from_secs(5),
45+
intensity: GamepadRumbleIntensity::MAX,
46+
});
47+
}
48+
}
49+
```
50+
51+
The `GamepadRumbleRequest::Add` event triggers a force-feedback motor,
52+
controlling how long the vibration should last, the motor to activate,
53+
and the vibration strength. `GamepadRumbleRequest::Stop` immediately stops all motors.
54+
55+
[`gilrs`]: https://crates.io/crates/gilrs
2156

2257
## Morph Targets
2358

0 commit comments

Comments
 (0)