fix cheats/gauges relative to Jupiter (which has no LinearVelocity)

This commit is contained in:
yuni 2024-11-28 04:39:46 +01:00
parent 3a7badf45b
commit 1bf83b424f
2 changed files with 21 additions and 3 deletions

View file

@ -472,8 +472,20 @@ fn handle_cheats(
if key_input.just_pressed(settings.key_cheat_stop) {
gforce.ignore_gforce_seconds = 1.0;
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;
}
}
}

View file

@ -841,7 +841,7 @@ fn update_speedometer(
jupiter_pos: Res<game::JupiterPos>,
q_camera: Query<(&LinearVelocity, &Position), With<actor::PlayerCamera>>,
q_player: Query<&actor::ExperiencesGForce, With<actor::Player>>,
q_target: Query<&LinearVelocity, With<IsTargeted>>,
q_target: Query<Option<&LinearVelocity>, With<IsTargeted>>,
mut q_speedometer: Query<&mut Style, (With<Speedometer>, Without<Speedometer2>)>,
mut q_speedometer2: Query<&mut Style, (With<Speedometer2>, Without<Speedometer>)>,
mut q_node_speed: Query<&mut Text, With<NodeSpeedometerText>>,
@ -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 {