From c8358488c2d2cf4ca430306d5d256bd0bba33381 Mon Sep 17 00:00:00 2001 From: Joe Ardent Date: Sun, 19 Feb 2023 14:21:41 -0800 Subject: [PATCH] make speed display according only to forward velocity, not total linear vel --- src/ui.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ui.rs b/src/ui.rs index 507dbe1..24c88cd 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -1,6 +1,6 @@ use bevy::prelude::{ AlignSelf, App, AssetServer, Color, Commands, Component, Plugin, Query, Res, Style, Text, - TextBundle, TextSection, TextStyle, With, + TextBundle, TextSection, TextStyle, Transform, With, }; #[cfg(feature = "inspector")] use bevy_inspector_egui::quick::WorldInspectorPlugin; @@ -39,12 +39,13 @@ fn setup_ui(mut commands: Commands, asset_server: Res) { } fn update_ui( - state_query: Query<&Velocity, With>, + state_query: Query<(&Velocity, &Transform), With>, mut text_query: Query<&mut Text, With>, ) { let mut text = text_query.single_mut(); - let state = state_query.single(); - text.sections[0].value = format!("spd: {:.2}", state.linvel.length()); + let (velocity, xform) = state_query.single(); + let speed = velocity.linvel.dot(xform.forward()); + text.sections[0].value = format!("spd: {:.2}", speed); } pub struct CyberUIPlugin;