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