fix hud speed display

This commit is contained in:
yuni 2024-03-30 17:19:11 +01:00
parent e4a3b92941
commit af2f43b9f9

View file

@ -1,6 +1,7 @@
use crate::{settings, actor, audio, nature};
use bevy::prelude::*;
use bevy::diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin};
use bevy_xpbd_3d::prelude::*;
use std::collections::VecDeque;
use std::time::SystemTime;
@ -370,7 +371,8 @@ fn update(
diagnostics: Res<DiagnosticsStore>,
time: Res<Time>,
mut log: ResMut<Log>,
player: Query<(&actor::Suit, &actor::LifeForm, &actor::Actor), With<actor::Player>>,
player: Query<(&actor::Suit, &actor::LifeForm), With<actor::Player>>,
q_camera: Query<&LinearVelocity, With<actor::PlayerCamera>>,
mut timer: ResMut<FPSUpdateTimer>,
mut query: Query<&mut Text, With<GaugesText>>,
q_choices: Query<&ChoiceAvailable>,
@ -380,9 +382,11 @@ fn update(
) {
// TODO only when hud is actually on
if timer.0.tick(time.delta()).just_finished() || log.needs_rerendering {
let q_camera_result = q_camera.get_single();
let player = player.get_single();
if player.is_ok() {
let (suit, lifeform, actor) = player.unwrap();
if player.is_ok() && q_camera_result.is_ok() {
let (suit, lifeform) = player.unwrap();
let cam_v = q_camera_result.unwrap();
for mut text in &mut query {
if let Some(fps) = diagnostics.get(&FrameTimeDiagnosticsPlugin::FPS) {
if let Some(value) = fps.smoothed() {
@ -409,7 +413,7 @@ fn update(
text.sections[10].value = format!("{all_actors:.0}");
let integrity = suit.integrity * 100.0;
text.sections[12].value = format!("{integrity:.0}%");
let speed = actor.v.length();
let speed = cam_v.length();
let kmh = speed * 60.0 * 60.0 / 1000.0;
text.sections[14].value = format!("{speed:.0}m/s | {kmh:.0}km/h");
}