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-dev | 2022年11月20日 |
#212 在 游戏开发
145 每月下载量
1MB
477 行
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 },
));
...
}
演示
依赖项
~30MB
~564K SLoC