From 7431c4f59479e093e8d6de0527e682103dbc8579 Mon Sep 17 00:00:00 2001 From: hut Date: Sat, 30 Mar 2024 16:41:22 +0100 Subject: [PATCH] refactoring camera::run_camera_controller --- src/camera.rs | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/camera.rs b/src/camera.rs index 09aa42a..d36bcd8 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -15,7 +15,8 @@ impl Plugin for CameraControllerPlugin { app.add_systems(Update, handle_input); app.add_systems(Update, manage_player_actor); app.add_systems(Update, sync_camera_to_player); - app.add_systems(Update, run_camera_controller); + app.add_systems(Update, update_fov); + app.add_systems(Update, apply_input_to_player); } } @@ -68,6 +69,17 @@ pub fn sync_camera_to_player( } } +pub fn update_fov( + q_player: Query<&actor::LifeForm, With>, + mut q_camera: Query<&mut Projection, With>, +) { + if let (Ok(lifeform), Ok(mut projection)) = (q_player.get_single(), q_camera.get_single_mut()) + { + let fov = (lifeform.adrenaline.powf(3.0) * 45.0 + 45.0).to_radians(); + *projection = Projection::Perspective(PerspectiveProjection { fov: fov, ..default() }); + } +} + pub fn handle_input( keyboard_input: Res>, mut settings: ResMut, @@ -96,7 +108,7 @@ fn manage_player_actor( } #[allow(clippy::too_many_arguments)] -fn run_camera_controller( +fn apply_input_to_player( time: Res