From 7514a3d7fe91ab7432ef25b623b66745b822d94e Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Fri, 22 Dec 2023 21:53:57 +0100 Subject: [PATCH] Reorient "up" axis when moving --- src/lib.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 15206b1..e02b85e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -326,14 +326,21 @@ fn reposition_compass( fn update_camera_orientations( mut movement_settings: ResMut, - fly_cam: Query>, + mut fly_cam: Query>, space: Res, ) { - movement_settings.up = fly_cam - .single() // the only FlyCam's calactic position + // the only FlyCam's calactic position + let mut fly_cam = fly_cam.single_mut(); + + let up = fly_cam .position_double(&space) .normalize() // direction from galactic NULL = from the Earth center .as_vec3(); + movement_settings.up = up; + + // Reorient "up" axis without introducing other rotations. + let forward = fly_cam.transform.forward(); + fly_cam.transform.look_to(forward, up); } fn pull_to_ground(