Skip to content

Commit

Permalink
Merge pull request #35 from sburris0/bevy_0.11
Browse files Browse the repository at this point in the history
Update to bevy 0.11 and add wasm support
  • Loading branch information
sburris0 committed Oct 8, 2023
2 parents 680247f + 4ed8bce commit 91fc66d
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 32 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_flycam"
version = "0.10.1"
version = "0.11.0"
authors = ["Spencer Burris <sburris@posteo.net>"]
edition = "2021"
license = "ISC"
Expand All @@ -13,7 +13,7 @@ categories = ["game-engines", "game-development"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
bevy = { version = "0.10", default-features = false, features = ["bevy_render", "bevy_core_pipeline", "bevy_asset"] }
bevy = { version = "0.11", default-features = false, features = ["bevy_render", "bevy_core_pipeline", "bevy_asset"] }

[dev-dependencies]
bevy = { version = "0.10", default-features = false, features = ["x11", "wayland", "bevy_pbr", "bevy_core_pipeline", "bevy_asset"] }
bevy = { version = "0.11", default-features = false, features = ["x11", "wayland", "bevy_pbr", "bevy_core_pipeline", "bevy_asset", "ktx2", "zstd", "tonemapping_luts"] }
44 changes: 36 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
![Crates.io](https://img.shields.io/crates/l/bevy_flycam)
![docs.rs](https://img.shields.io/docsrs/bevy_flycam)

A basic first-person fly camera for Bevy 0.10
A basic first-person fly camera for Bevy 0.11

## Controls

Expand All @@ -29,15 +29,15 @@ There are a few notable differences from [bevy_fly_camera](https://github.com/mc

```toml
[dependencies]
bevy = "0.10"
bevy = "0.11"
bevy_flycam = "*"
```

or

```toml
[dependencies]
bevy = "0.10"
bevy = "0.11"
bevy_flycam = { git = "https://github.com/sburris0/bevy_flycam" }
```

Expand All @@ -47,26 +47,28 @@ There are a few notable differences from [bevy_fly_camera](https://github.com/mc
use bevy_flycam::prelude::*;
```

This will spawn a camera for you.
Use `NoCameraPlayerPlugin` if you do not want this and make sure to use `.insert(FlyCam)` on your own camera or else this plugin won't know what to move.

3. Add the `PlayerPlugin`:

```rust
#[bevy_main]
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(PlayerPlugin)
.add_plugins(PlayerPlugin)
.run();
}
```

Note that `PlayerPlugin` will spawn a camera for you. See [Using your own camera](#using-your-own-camera) for details on how to
use a pre-existing one.

Alternatively you can see the example `basic.rs` or `scroll.rs` located in the examples folder.
You can run the example by cloning this repository and run the command: `cargo run --release --example basic`

## Customization

### Movement and keybindings

To modify player movement speed or mouse sensitivity add it as a resource. </br>
Same thing goes for the keybindings used for moving the camera.

Expand All @@ -75,7 +77,7 @@ Same thing goes for the keybindings used for moving the camera.
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(PlayerPlugin)
.add_plugins(PlayerPlugin)
.insert_resource(MovementSettings {
sensitivity: 0.00015, // default: 0.00012
speed: 12.0, // default: 12.0
Expand All @@ -89,13 +91,39 @@ fn main() {
}
```

### Using your own camera

You can also use `NoCameraPlayerPlugin` if you want to use your own camera. Be sure to add the `FlyCam` component to your own camera or else this plugin won't know what to move.

```Rust
#[bevy_main]
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(NoCameraPlayerPlugin)
.add_systems(Startup, setup)
.run();
}

fn setup(mut commands: Commands) {
commands.spawn((
Camera3dBundle {
transform: Transform::from_xyz(0.0, 2.0, 0.5),
..default()
},
FlyCam
));
}
```

## Support

[![Bevy tracking](https://img.shields.io/badge/Bevy%20tracking-released%20version-lightblue)](https://github.com/bevyengine/bevy/blob/main/docs/plugins_guidelines.md#main-branch-tracking)

bevy_flycam's crate version follows bevy's minor version as shown:
| bevy | bevy_flycam |
| :-- | :-- |
| `0.11.0` | `0.11.0` |
| `0.10.1` | `0.10.1` |

## Contributing
Expand Down
4 changes: 2 additions & 2 deletions examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ fn main() {
App::new()
.insert_resource(Msaa::Sample4)
.add_plugins(DefaultPlugins)
.add_plugin(PlayerPlugin)
.add_plugins(PlayerPlugin)
.insert_resource(MovementSettings {
sensitivity: 0.00015, // default: 0.00012
speed: 12.0, // default: 12.0
})
.add_system(setup.on_startup())
.add_systems(Startup, setup)
.run();
}

Expand Down
4 changes: 2 additions & 2 deletions examples/key_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn main() {
App::new()
.insert_resource(Msaa::Sample4)
.add_plugins(DefaultPlugins)
.add_plugin(PlayerPlugin)
.add_plugins(PlayerPlugin)
.insert_resource(MovementSettings {
sensitivity: 0.00015, // default: 0.00012
speed: 12.0, // default: 12.0
Expand All @@ -19,7 +19,7 @@ fn main() {
move_descend: KeyCode::Q,
..Default::default()
})
.add_startup_system(setup)
.add_systems(Startup, setup)
.run();
}

Expand Down
12 changes: 6 additions & 6 deletions examples/scroll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ fn main() {
.insert_resource(Msaa::Sample4)
.add_plugins(DefaultPlugins)
//NoCameraPlayerPlugin as we provide the camera
.add_plugin(NoCameraPlayerPlugin)
.add_plugins(NoCameraPlayerPlugin)
.insert_resource(MovementSettings {
..Default::default()
})
// Setting initial state
.add_state::<ScrollType>()
.add_system(setup.on_startup())
.add_system(switch_scroll_type)
.add_system(scroll)
.add_systems(Startup, setup)
.add_systems(Update, switch_scroll_type)
.add_systems(Update, scroll)
.run();
}

Expand Down Expand Up @@ -78,7 +78,7 @@ fn switch_scroll_type(
keyboard_input: Res<Input<KeyCode>>,
) {
if keyboard_input.just_pressed(KeyCode::Z) {
let result = match scroll_type.0 {
let result = match scroll_type.get() {
ScrollType::MovementSpeed => ScrollType::Zoom,
ScrollType::Zoom => ScrollType::MovementSpeed,
};
Expand All @@ -96,7 +96,7 @@ fn scroll(
mut query: Query<(&FlyCam, &mut Projection)>,
) {
for event in mouse_wheel_events.iter() {
if scroll_type.0 == ScrollType::MovementSpeed {
if *scroll_type.get() == ScrollType::MovementSpeed {
settings.speed = (settings.speed + event.y * 0.1).abs();
println!("Speed: {:?}", settings.speed);
} else {
Expand Down
22 changes: 11 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl Default for KeyBindings {
move_left: KeyCode::A,
move_right: KeyCode::D,
move_ascend: KeyCode::Space,
move_descend: KeyCode::LShift,
move_descend: KeyCode::ShiftLeft,
toggle_grab_cursor: KeyCode::Escape,
}
}
Expand Down Expand Up @@ -212,11 +212,11 @@ impl Plugin for PlayerPlugin {
app.init_resource::<InputState>()
.init_resource::<MovementSettings>()
.init_resource::<KeyBindings>()
.add_system(setup_player.on_startup())
.add_system(initial_grab_cursor.on_startup())
.add_system(player_move)
.add_system(player_look)
.add_system(cursor_grab);
.add_systems(Startup, setup_player)
.add_systems(Startup, initial_grab_cursor)
.add_systems(Update, player_move)
.add_systems(Update, player_look)
.add_systems(Update, cursor_grab);
}
}

Expand All @@ -227,10 +227,10 @@ impl Plugin for NoCameraPlayerPlugin {
app.init_resource::<InputState>()
.init_resource::<MovementSettings>()
.init_resource::<KeyBindings>()
.add_system(initial_grab_cursor.on_startup())
.add_system(initial_grab_on_flycam_spawn.on_startup())
.add_system(player_move)
.add_system(player_look)
.add_system(cursor_grab);
.add_systems(Startup, initial_grab_cursor)
.add_systems(Startup, initial_grab_on_flycam_spawn)
.add_systems(Update, player_move)
.add_systems(Update, player_look)
.add_systems(Update, cursor_grab);
}
}

0 comments on commit 91fc66d

Please sign in to comment.