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

bevy_fps_controller

Bevy插件,添加了源自Source引擎的FPS移动控制器

18次发布

0.3.0 2024年7月10日
0.2.5 2024年2月25日
0.2.4 2023年12月23日
0.2.3 2023年10月24日
0.1.4-dev2022年11月20日

#212游戏开发

Download history 7/week @ 2024-05-20 7/week @ 2024-06-03 5/week @ 2024-06-10 143/week @ 2024-06-17 23/week @ 2024-06-24 103/week @ 2024-07-01 138/week @ 2024-07-08 13/week @ 2024-07-15 19/week @ 2024-07-22 87/week @ 2024-07-29 16/week @ 2024-08-05 23/week @ 2024-08-12

145 每月下载量

MIT/Apache

1MB
477

Rust crates.io

Bevy FPS Controller

受Source引擎移动启发,此插件实现了适合FPS游戏的移动功能。

欢迎提交问题/PR!

特性

  • 空中侧滑和兔跳(按住跳跃键)
  • 支持斜坡地面
  • 蹲下(防止掉落),冲刺
  • 无碰撞模式
  • 可配置设置

示例

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 },
    ));
    ...
}

演示

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

由我的其他项目使用:https://github.com/qhdwight/voxel-game-rs

依赖项

~30MB
~564K SLoC