#camera #bevy #camera-control #3d #gamedev #game-engine

bevy_flycam

Basic first-person fly camera for the Bevy game engine

19 releases (12 breaking)

0.13.0 Mar 7, 2024
0.12.0 Nov 5, 2023
0.11.0 Oct 8, 2023
0.10.1 Apr 10, 2023
0.4.0 Feb 15, 2021

#258 in Game dev

Download history 108/week @ 2023-12-22 50/week @ 2023-12-29 102/week @ 2024-01-05 121/week @ 2024-01-12 95/week @ 2024-01-19 76/week @ 2024-01-26 83/week @ 2024-02-02 126/week @ 2024-02-09 240/week @ 2024-02-16 220/week @ 2024-02-23 279/week @ 2024-03-01 297/week @ 2024-03-08 203/week @ 2024-03-15 161/week @ 2024-03-22 276/week @ 2024-03-29 119/week @ 2024-04-05

802 downloads per month
Used in bevy_procedural_grass

ISC license

28KB
199 lines

bevy_flycam

Crates.io Crates.io docs.rs

A basic first-person fly camera for Bevy 0.13

Controls

  • WASD to move horizontally
  • SPACE to ascend
  • LSHIFT to descend
  • ESC to grab/release cursor.

Comparison

There are a few notable differences from bevy_fly_camera...

  • No linear interpolation
  • Cursor grabbing
  • Shorter code
  • Single-line setup
  • A tiny bit faster?

Usage

  1. Add to Cargo.toml or copy lib.rs to your own file

    [dependencies]
    bevy = "0.13"
    bevy_flycam = "*"
    

    or

    [dependencies]
    bevy = "0.13"
    bevy_flycam = { git = "https://github.com/sburris0/bevy_flycam" }
    
  2. Include the prelude:

    use bevy_flycam::prelude::*;
    
  3. Add the PlayerPlugin:

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

Note that PlayerPlugin will spawn a camera for you. See 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.
Same thing goes for the keybindings used for moving the camera.

#[bevy_main]
fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_plugins(PlayerPlugin)
        .insert_resource(MovementSettings {
            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();
}

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.

#[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

bevy_flycam's crate version follows bevy's minor version as shown:

bevy bevy_flycam
0.13.0 0.13.0
0.12.0 0.12.0
0.11.0 0.11.0
0.10.1 0.10.1

Contributing

PRs are very welcome.

Dependencies

~38–79MB
~1M SLoC