/bevy_fps_controller

Source engine inspired Bevy FPS controller plugin

Primary LanguageRustApache License 2.0Apache-2.0

Rust crates.io

Bevy FPS Controller

Inspired from Source engine movement, this plugin implements movement suitable for FPS games.

⚠️ Feedback requested! Still in early stages, feel free to make issues/PRs

Features

  • Air strafing and bunny hopping (hold down jump key)
  • Support for sloped ground
  • Crouching (prevents falling off ledges), sprinting
  • Noclip mode
  • Configurable settings

Examples

See main.rs

cargo run --example minimal
use bevy::prelude::*;
use bevy_rapier3d::prelude::*;

use bevy_fps_controller::controller::*;

fn main() {
    App::new()
        ...
        .add_plugin(RapierPhysicsPlugin::<NoUserData>::default())
        .add_plugin(FpsControllerPlugin)
        .add_startup_system(setup)
        ...
}

fn setup(mut commands: Commands, ...) {
    ...
    commands.spawn((
        Collider::capsule(Vec3::Y * 0.5, Vec3::Y * 1.5, 0.5),
        Friction {
            coefficient: 0.0,
            combine_rule: CoefficientCombineRule::Min,
        },
        Restitution {
            coefficient: 0.0,
            combine_rule: CoefficientCombineRule::Min,
        },
        ActiveEvents::COLLISION_EVENTS,
        Velocity::zero(),
        RigidBody::Dynamic,
        Sleeping::disabled(),
        LockedAxes::ROTATION_LOCKED,
        AdditionalMassProperties::Mass(1.0),
        GravityScale(0.0),
        Ccd { enabled: true }, // Prevent clipping when going fast
        TransformBundle::from_transform(Transform::from_xyz(0.0, 3.0, 0.0)),
        LogicalPlayer(0),
        FpsControllerInput {
            pitch: -TAU / 12.0,
            yaw: TAU * 5.0 / 8.0,
            ..default()
        },
        FpsController { ..default() }
    ));
    commands.spawn((
        Camera3dBundle::default(),
        RenderPlayer(0),
    ));
    ...
}

Demo

controller_demo.mp4

Used by my other project: https://github.com/qhdwight/voxel-game-rs