diff --git a/src/game.rs b/src/game.rs index a961a1b..8e2bbcf 100644 --- a/src/game.rs +++ b/src/game.rs @@ -472,7 +472,19 @@ fn handle_cheats( if key_input.just_pressed(settings.key_cheat_stop) { gforce.ignore_gforce_seconds = 1.0; - v.0 = nature::orbital_velocity(pos.0 - jupiter_pos.0, nature::JUPITER_MASS); + if let Ok((_, _, target_v)) = q_target.get_single() { + if let Some(target_v) = target_v { + // We targeted something. Match its velocity. + v.0 = target_v.0; + } else { + // We targeted something, but it has no velocity. + v.0 = DVec3::ZERO; + } + } + else { + // We aren't targeting anything. Match orbital velocity. + v.0 = nature::orbital_velocity(pos.0 - jupiter_pos.0, nature::JUPITER_MASS); + } } if key_input.pressed(settings.key_cheat_speed) || key_input.pressed(settings.key_cheat_speed_backward) @@ -498,6 +510,8 @@ fn handle_cheats( pos.0 = **target_pos + offset; if let Some(target_v) = target_v { *v = target_v.clone(); + } else { + v.0 = DVec3::ZERO; } } } diff --git a/src/hud.rs b/src/hud.rs index 05fd000..6f11b66 100644 --- a/src/hud.rs +++ b/src/hud.rs @@ -841,7 +841,7 @@ fn update_speedometer( jupiter_pos: Res, q_camera: Query<(&LinearVelocity, &Position), With>, q_player: Query<&actor::ExperiencesGForce, With>, - q_target: Query<&LinearVelocity, With>, + q_target: Query, With>, mut q_speedometer: Query<&mut Style, (With, Without)>, mut q_speedometer2: Query<&mut Style, (With, Without)>, mut q_node_speed: Query<&mut Text, With>, @@ -904,7 +904,11 @@ fn update_speedometer( // Velocity relative to target speed_text.sections[2].value = if let Ok(target_v) = q_target.get_single() { - let delta_v = (target_v.0 - cam_v.0).length(); + let delta_v = if let Some(target_v) = target_v { + (target_v.0 - cam_v.0).length() + } else { + cam_v.0.length() + }; if delta_v > 0.0001 { format!("Δv {}\n", nature::readable_speed(delta_v)) } else {