Skip to content

Commit

Permalink
Merge pull request #29 from BlackPhlox/bevy_0.10_merge
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackPhlox committed Apr 3, 2023
2 parents c720d2f + 7f2d570 commit 68eafb4
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 125 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.0", default-features = false, features = ["bevy_render", "bevy_core_pipeline", "bevy_asset"] }
bevy = { version = "0.10", default-features = false, features = ["bevy_render", "bevy_core_pipeline", "bevy_asset"] }

[dev-dependencies]
bevy = { version = "0.10.0", default-features = false, features = ["x11", "wayland", "bevy_pbr", "bevy_core_pipeline", "bevy_asset"] }
bevy = { version = "0.10", default-features = false, features = ["x11", "wayland", "bevy_pbr", "bevy_core_pipeline", "bevy_asset"] }
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ bevy = "0.10"
bevy_flycam = { git = "https://github.com/sburris0/bevy_flycam" }
```

2. Include the `PlayerPlugin`
2. Include the prelude:
```rust
use bevy_flycam::PlayerPlugin;
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.
Expand All @@ -59,7 +59,8 @@ Alternatively you can see the example `basic.rs` or `scroll.rs` located in the e
You can run the example by cloning this repository and run the command: `cargo run --release --example basic`

## Customization
To modify player movement speed or mouse sensitivity, import `bevy_flycam::MovementSettings` and add it as a resource:
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.
```Rust
#[bevy_main]
fn main() {
Expand All @@ -70,17 +71,22 @@ fn main() {
sensitivity: 0.00015, // default: 0.00012
speed: 12.0, // default: 12.0
})
.insert_resource(KeyBindings {
move_ascend: KeyCode::E,
move_descend: KeyCode::Q,
..Default::default()
})
.run();
}
```

# 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 X version as shown:
bevy_flycam's crate version follows bevy's minor version as shown:
| bevy | bevy_flycam |
| :-- | :-- |
| `0.10.0` | `0.10` |
| `0.10.X` | `0.10` |

## Contributing
PRs are very welcome.
11 changes: 6 additions & 5 deletions examples/basic.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use bevy::prelude::*;
use bevy_flycam::MovementSettings;
use bevy_flycam::PlayerPlugin;
use bevy_flycam::prelude::*;

//From bevy examples:
//https://github.com/bevyengine/bevy/blob/latest/examples/3d/3d_scene.rs
Expand All @@ -25,21 +24,23 @@ fn setup(
mut materials: ResMut<Assets<StandardMaterial>>,
) {
// plane
commands.spawn(PbrBundle {
commands.spawn((PbrBundle {
mesh: meshes.add(Mesh::from(shape::Plane {
size: 5.0,
subdivisions: 0,
..Default::default()
})),
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
..Default::default()
});
},));

// cube
commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })),
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()),
transform: Transform::from_xyz(0.0, 0.5, 0.0),
..Default::default()
});

// light
commands.spawn(PointLightBundle {
transform: Transform::from_xyz(4.0, 8.0, 4.0),
Expand Down
38 changes: 18 additions & 20 deletions examples/key_bindings.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,25 @@
// Remove the line below if you are copying this to your own project
extern crate bevy_flycam;

use bevy::prelude::*;
use bevy_flycam::PlayerPlugin;
use bevy_flycam::{KeyBindings, MovementSettings};
use bevy_flycam::prelude::*;

//From bevy examples:
//https://github.com/bevyengine/bevy/blob/latest/examples/3d/3d_scene.rs

fn main() {
App::build()
.insert_resource(Msaa { samples: 4 })
App::new()
.insert_resource(Msaa::Sample4)
.add_plugins(DefaultPlugins)
.add_plugin(PlayerPlugin)
.insert_resource(MovementSettings {
sensitivity: 0.00015, // default: 0.00012
speed: 12.0, // default: 12.0
})
// Unreal movement layout
.insert_resource(KeyBindings {
move_forward: KeyCode::A,
move_backward: KeyCode::Z,
move_left: KeyCode::Q,
move_right: KeyCode::W,
move_ascend: KeyCode::C,
move_descend: KeyCode::V,
toggle_grab_cursor: KeyCode::F,
move_ascend: KeyCode::E,
move_descend: KeyCode::Q,
..Default::default()
})
.add_startup_system(setup.system())
.add_startup_system(setup)
.run();
}

Expand All @@ -37,20 +30,25 @@ fn setup(
mut materials: ResMut<Assets<StandardMaterial>>,
) {
// plane
commands.spawn_bundle(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Plane { size: 5.0 })),
commands.spawn((PbrBundle {
mesh: meshes.add(Mesh::from(shape::Plane {
size: 5.0,
..Default::default()
})),
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
..Default::default()
});
},));

// cube
commands.spawn_bundle(PbrBundle {
commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })),
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()),
transform: Transform::from_xyz(0.0, 0.5, 0.0),
..Default::default()
});

// light
commands.spawn_bundle(LightBundle {
commands.spawn(PointLightBundle {
transform: Transform::from_xyz(4.0, 8.0, 4.0),
..Default::default()
});
Expand Down
28 changes: 15 additions & 13 deletions examples/scroll.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bevy::{input::mouse::MouseWheel, prelude::*, render::camera::Projection};
use bevy_flycam::{FlyCam, MovementSettings, NoCameraPlayerPlugin};
use bevy::{input::mouse::MouseWheel, prelude::*};
use bevy_flycam::prelude::*;

// From bevy examples:
// https://github.com/bevyengine/bevy/blob/latest/examples/3d/3d_scene.rs
Expand Down Expand Up @@ -35,35 +35,37 @@ fn setup(
mut materials: ResMut<Assets<StandardMaterial>>,
) {
// plane
commands.spawn(PbrBundle {
commands.spawn((PbrBundle {
mesh: meshes.add(Mesh::from(shape::Plane {
size: 5.0,
subdivisions: 0,
..Default::default()
})),
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
..Default::default()
});
},));

// cube
commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })),
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()),
transform: Transform::from_xyz(0.0, 0.5, 0.0),
..Default::default()
});

// light
commands.spawn(PointLightBundle {
transform: Transform::from_xyz(4.0, 8.0, 4.0),
..Default::default()
});

// camera
let camera = Camera3dBundle {
transform: Transform::from_xyz(-2.0, 5.0, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
..Default::default()
};

// add plugin
commands.spawn(camera).insert(FlyCam);
// add camera
commands.spawn((
Camera3dBundle {
transform: Transform::from_xyz(-2.0, 5.0, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
..Default::default()
},
FlyCam,
));

info!("Press 'Z' to switch between Movement Speed and Zoom");
info!("Changing the selected value by scrolling the mousewheel");
Expand Down

0 comments on commit 68eafb4

Please sign in to comment.