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;