Crates.io | bevy_trauma_shake |
lib.rs | bevy_trauma_shake |
version | |
source | src |
created_at | 2023-11-18 21:04:42.605655 |
updated_at | 2024-12-08 13:56:27.270409 |
description | A plugin for shaking 2d cameras |
homepage | |
repository | https://github.com/johanhelsing/bevy_trauma_shake |
max_upload_size | |
id | 1040714 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Add camera shakes to your 2d Bevy game with three lines of code.
Add the plugin:
app.add_plugins(TraumaPlugin);
Simply add a component to your camera:
commands.spawn((Camera2dBundle::default(), Shake::default()));
Make it shake:
fn shake(mut shake: Query<&mut Shake>, keys: Res<ButtonInput<KeyCode>>) {
if keys.just_pressed(KeyCode::Space) {
shake.single_mut().add_trauma(0.2);
}
}
There is also a convenience system param for applying trauma to all Shake
s:
fn shake(mut shake: Shakes, keys: Res<ButtonInput<KeyCode>>) {
if keys.just_pressed(KeyCode::Space) {
shakes.add_trauma(0.2);
}
}
And an event, if you prefer that:
fn shake(mut trauma: EventWriter<TraumaEvent>, keys: Res<ButtonInput<KeyCode>>) {
if keys.just_pressed(KeyCode::Space) {
trauma.send(0.2.into());
}
}
And even a command:
fn shake(mut commands: Commands, keys: Res<ButtonInput<KeyCode>>) {
if keys.just_pressed(KeyCode::Space) {
info!("Adding small trauma");
commands.add_trauma(0.2);
}
}
Maybe I went a little overboard and I should remove one of those ways, in any case, they can be toggled through the features: system_param
, events
, commands
.
Optionally add ShakeSettings
, if you're not happy with the defaults.
commands.spawn((
Name::new("Camera"),
Camera2dBundle::default(),
Shake::default(),
ShakeSettings {
amplitude: 200.,
trauma_power: 3.,
decay_per_second: 0.3,
frequency: 4.,
octaves: 2,
},
PanCam::default(),
));
The main
branch targets the latest bevy release.
bevy | bevy_trauma_shake |
---|---|
0.15 | 0.4, main |
0.14 | 0.3 |
0.13 | 0.2 |
0.12 | 0.1 |
bevy_trauma_shake
is dual-licensed under either
at your option.
bevy_camera_shake
: 2D and 3D shakes and more configuration options. I used this a lot for reference, but I wanted a simpler API.PRs welcome!