From 05d32c943d3b87b49ac61b23567dbac7ade30d98 Mon Sep 17 00:00:00 2001 From: extrawurst Date: Tue, 24 Jun 2025 17:42:36 +0200 Subject: [PATCH] fix camera angles to prevent char from disappearing --- src/camera.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/camera.rs b/src/camera.rs index 45eeff2..7c96aeb 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -30,12 +30,17 @@ struct CameraUi; pub struct MainCamera { dir: Dir3, distance: f32, + target_offset: Vec3, } impl MainCamera { fn new(arm: Vec3) -> Self { let (dir, distance) = Dir3::new_and_length(arm).expect("invalid arm length"); - Self { dir, distance } + Self { + dir, + distance, + target_offset: Vec3::new(0., 2., 0.), + } } } @@ -57,7 +62,7 @@ pub fn plugin(app: &mut App) { fn startup(mut commands: Commands) { commands.spawn(( Camera3d::default(), - MainCamera::new(Vec3::new(0., 2.5, -13.)), + MainCamera::new(Vec3::new(0., 1.8, -15.)), CameraRotationInput::default(), )); } @@ -120,14 +125,14 @@ fn update( return; } - let target = target_q.translation; - let arm_tf = arm_rotation; let Ok((camera, mut cam_transform, cam_rotation_input)) = cam.single_mut() else { return; }; + let target = target_q.translation + camera.target_offset; + let direction = arm_tf.rotation * Quat::from_rotation_y(cam_rotation_input.x) * camera.dir; let max_distance = camera.distance;