2025-05-14 23:14:41 +02:00
|
|
|
//! Sets up the game's camera controls etc.
|
2025-05-21 15:56:58 +02:00
|
|
|
//! Uses [bevy_third_person_camera](https://lib.rs/crates/bevy_third_person_camera)
|
|
|
|
use bevy::prelude::*;
|
|
|
|
use bevy_third_person_camera::*;
|
2025-05-14 23:14:41 +02:00
|
|
|
|
2025-05-21 15:56:58 +02:00
|
|
|
use crate::AppState;
|
2025-05-14 23:14:41 +02:00
|
|
|
|
|
|
|
use super::GameplaySet;
|
|
|
|
|
|
|
|
pub fn plugin(app: &mut App) {
|
2025-05-21 15:56:58 +02:00
|
|
|
app.add_plugins(ThirdPersonCameraPlugin)
|
|
|
|
.add_systems(
|
|
|
|
OnEnter(AppState::Ingame),
|
|
|
|
setup_game_camera.in_set(GameplaySet),
|
2025-05-14 23:14:41 +02:00
|
|
|
)
|
2025-05-21 15:56:58 +02:00
|
|
|
.add_systems(OnExit(AppState::Ingame), remove_tpc.in_set(GameplaySet));
|
2025-05-14 23:14:41 +02:00
|
|
|
}
|
|
|
|
|
2025-05-21 15:56:58 +02:00
|
|
|
/// Adds [ThirdPersonCamera] to our existing camera.
|
|
|
|
pub fn setup_game_camera(mut c: Commands, cam: Single<Entity, With<Camera3d>>) {
|
|
|
|
c.entity(*cam).insert(ThirdPersonCamera::default());
|
|
|
|
info!("Third person camera set up!")
|
2025-05-14 23:14:41 +02:00
|
|
|
}
|
|
|
|
|
2025-05-21 15:56:58 +02:00
|
|
|
/// Removes [ThirdPersonCamera] from the camera.
|
|
|
|
pub fn remove_tpc(mut c: Commands, cam: Single<Entity, (With<Camera3d>, With<ThirdPersonCamera>)>) {
|
|
|
|
c.entity(*cam).remove::<ThirdPersonCamera>();
|
2025-05-14 23:14:41 +02:00
|
|
|
}
|