From 6c9482a3efa6c68c5c58062647eb26d2a6f77fa0 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 fa60235..314d646 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -316,14 +316,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(