Skip to content

Commit

Permalink
Reorient "up" axis when moving
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Dec 22, 2023
1 parent 0e5ca96 commit 7514a3d
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,14 +326,21 @@ fn reposition_compass(

fn update_camera_orientations(
mut movement_settings: ResMut<MovementSettings>,
fly_cam: Query<GalacticTransform, With<FlyCam>>,
mut fly_cam: Query<GalacticTransform, With<FlyCam>>,
space: Res<FloatingOriginSettings>,
) {
movement_settings.up = fly_cam
.single() // the only FlyCam's calactic position <grid,f32>
// the only FlyCam's calactic position <grid,f32>
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(
Expand Down

0 comments on commit 7514a3d

Please sign in to comment.