make speed display according only to forward velocity, not total linear vel

This commit is contained in:
Joe Ardent 2023-02-19 14:21:41 -08:00
parent 6fd2c17413
commit c8358488c2

View file

@ -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<AssetServer>) {
}
fn update_ui(
state_query: Query<&Velocity, With<CyberBikeBody>>,
state_query: Query<(&Velocity, &Transform), With<CyberBikeBody>>,
mut text_query: Query<&mut Text, With<UpText>>,
) {
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;