#bevy-plugin #movement #fps #controller #source #game-engine #jump

bevy_fps_controller

Bevy plugin that adds a Source engine inspired FPS movement controller

18 releases

0.3.0 Jul 10, 2024
0.2.5 Feb 25, 2024
0.2.4 Dec 23, 2023
0.2.3 Oct 24, 2023
0.1.4-dev Nov 20, 2022

#246 in Game dev

Download history 13/week @ 2024-07-19 88/week @ 2024-07-26 22/week @ 2024-08-02 23/week @ 2024-08-09 3/week @ 2024-08-16 2/week @ 2024-08-30 4/week @ 2024-09-06 7/week @ 2024-09-13 50/week @ 2024-09-20 58/week @ 2024-09-27 12/week @ 2024-10-04 82/week @ 2024-10-11 12/week @ 2024-10-18 51/week @ 2024-10-25 15/week @ 2024-11-01

160 downloads per month

MIT/Apache

1MB
477 lines

Rust crates.io

Bevy FPS Controller

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

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 --release --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, ...) {
    ...
    let logical_entity = 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,
            FpsControllerInput {
                pitch: -TAU / 12.0,
                yaw: TAU * 5.0 / 8.0,
                ..default()
            },
            FpsController { ..default() }
        ))
        .insert(CameraConfig {
            height_offset: 0.0,
            radius_scale: 0.75,
        })
        .id();

    commands.spawn((
        Camera3dBundle::default(),
        RenderPlayer { logical_entity },
    ));
    ...
}

Demo

https://user-images.githubusercontent.com/20666629/221995601-2ec352fe-a8b0-4f8c-9a81-beaf898b2b41.mp4

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

Dependencies

~31MB
~591K SLoC