12个版本
0.1.11 | 2024年7月9日 |
---|---|
0.1.10 | 2024年2月25日 |
0.1.8 | 2024年1月5日 |
0.1.7 | 2023年11月11日 |
0.1.1 | 2023年7月30日 |
#4 in #orbit
每月下载量246
用于 2 Crate
40KB
505 代码行
Bevy 第三人称相机
- 目标
- 缩放
- 轨道
- 自定义偏移
- 光标锁定
- 自定义灵敏度
- 全面支持游戏手柄!
入门
添加 bevy_third_person_camera Crate
cargo add bevy_third_person_camera
导入 bevy_third_person_camera Crate
use bevy_third_person_camera::*;
添加 ThirdPersonPlugin
.add_plugins(ThirdPersonCameraPlugin)
将 ThirdPersonCamera 组件添加到相机实体
commands.spawn((
ThirdPersonCamera::default(),
Camera3dBundle::default()
));
将 ThirdPersonCameraTarget 组件添加到玩家
// Player
commands.spawn((
PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube::new(1.0))),
material: materials.add(Color::BLUE.into()),
transform: Transform::from_xyz(0.0, 0.5, 0.0),
..default()
},
ThirdPersonCameraTarget,
Player,
));
就这些!
示例
- 默认
- 自定义
cargo run --example <example name>
功能
偏移
offset
将分别偏移相机的 x 和 y 值。默认情况下禁用偏移。使用 offset_enabled: true
启用。
offset_enabled: true,
offset: Offset::new(0.5, 0.25),
offset_toggle_key: Some(KeyCode::T),
offset_toggle_speed: 5.0 // default
目标
瞄准计算使用 aim_zoom
和 zoom.min
的值。请注意,如果您更改 zoom.min
的值,即使 aim_zoom
的值保持不变,实际的缩放级别也会变化。默认情况下禁用瞄准。使用 aim_enabled: true
启用。
aim_enabled: true, // default
aim_speed: 3.0, // default
aim_zoom: 0.7, // default
aim_button: Some(MouseButton::Right), // default
zoom: Zoom::new(1.5, 3.0)
光标锁定
光标锁定功能允许鼠标光标在锁定、隐藏状态和未锁定、可见状态之间切换。当未锁定时,轨道功能被禁用,因此允许光标在窗口内自由移动,而不会破坏相机的变换。可以通过将 enable_cursor_lock_toggle 值设置为 false 来完全禁用此功能,并将光标锁定并隐藏。
cursor_lock_toggle_enabled: true,
cursor_lock_active: true,
cursor_lock_key: KeyCode::Space,
轨道
默认情况下启用轨道。但是,您可以设置 mouse_orbit_button_enabled
设置为 true
,轨道仅在按下 mouse_orbit_button
时激活。
自定义设置
大多数设置可以覆盖
let gamepad = Gamepad::new(0);
commands.spawn((
// These are the default settings
ThirdPersonCamera {
aim_enabled: false,
aim_button: Some(MouseButton::Right),
aim_speed: 3.0,
aim_zoom: 0.7,
cursor_lock_toggle_enabled: true,
cursor_lock_active: true,sa
cursor_lock_key: KeyCode::Space,
sensitivity: Vec2::new(1.0, 1.0),
mouse_orbit_button_enabled: false,
mouse_orbit_button: MouseButton::Middle,
offset_enabled: false,
offset: Offset::new(0.5, 0.4),
offset_toggle_speed: 5.0,
offset_toggle_key: Some(KeyCode::T), // default is None
zoom: Zoom::new(1.5, 3.0),
zoom_sensitivity: 1.0,
gamepad_settings: CameraGamepadSettings {
aim_button: Some(GamepadButton::new(gamepad, GamepadButtonType::LeftTrigger2)),
mouse_orbit_button: GamepadButton::new(gamepad, GamepadButtonType::LeftTrigger),
sensitivity: Vec2::new(7.0, 4.0),
offset_toggle_button: Some(GamepadButton::new(gamepad, GamepadButtonType::DPadRight)), // default is None
zoom_in_button: GamepadButton::new(gamepad, GamepadButtonType::DPadUp),
zoom_out_button: GamepadButton::new(gamepad, GamepadButtonType::DPadDown),
},
..default()
},
Camera3dBundle::default(),
));
默认控制
动作 | 鼠标/键盘 | 游戏手柄 | 默认启用 |
---|---|---|---|
放大 | 向上滚动 | 上方向键 | 是 |
缩小 | 向下滚动 | 方向键向下 | 是 |
目标 | 右鼠标按钮 | 左扳机 | 否 |
切换偏移量 | E | 方向键向右 | 否 |
光标锁定/解锁 | 空格 | 不适用 | 是 |
轨道按钮 | 中鼠标按钮 | 左护盖 | 否 |
Bevy 版本兼容性
bevy | bevy_third_person_camera |
---|---|
0.14 | 0.1.11 |
0.13 | 0.1.9 - 0.1.10 |
0.12 | 0.1.7 - 0.1.8 |
0.11 | 0.1.1 - 0.1.6 |
查看重大更改和更新,请参阅变更日志。
迁移指南
许可证
- MIT 许可证 (LICENSE-MIT 或 http://opensource.org/licenses/MIT)
- Apache 许可证 2.0 版 (LICENSE-APACHE 或 https://apache.ac.cn/licenses/LICENSE-2.0)
依赖
~23MB
~413K SLoC