Show correct speed in hud
This commit is contained in:
parent
e0ceb680b4
commit
40805e9775
1 changed files with 4 additions and 2 deletions
|
@ -34,15 +34,17 @@ fn speed_update_system(
|
||||||
rigid_body_set: Res<RigidBodySet>,
|
rigid_body_set: Res<RigidBodySet>,
|
||||||
mut text_query: Query<&mut Text, With<SpeedText>>,
|
mut text_query: Query<&mut Text, With<SpeedText>>,
|
||||||
player_query: Query<&RigidBodyHandleComponent, With<PlayerMarker>>,
|
player_query: Query<&RigidBodyHandleComponent, With<PlayerMarker>>,
|
||||||
|
time: Res<Time>,
|
||||||
) {
|
) {
|
||||||
for player in player_query.iter() {
|
for player in player_query.iter() {
|
||||||
// TODO: would be better to calculate this in a function in player somehow
|
// TODO: would be better to calculate this in a function in player somehow
|
||||||
let player_body = rigid_body_set.get(player.handle());
|
let player_body = rigid_body_set.get(player.handle());
|
||||||
let player_velocity = player_body.unwrap().linvel();
|
let player_velocity = player_body.unwrap().linvel();
|
||||||
let player_speed = Vec3::new(player_velocity.x, 0.0, player_velocity.z).length();
|
let player_velocity_2d = Vec3::new(player_velocity.x, 0.0, player_velocity.z);
|
||||||
|
let player_speed_2d = player_velocity_2d.length() / time.delta_seconds();
|
||||||
|
|
||||||
for mut text in text_query.iter_mut() {
|
for mut text in text_query.iter_mut() {
|
||||||
text.value = format!("{} m/s", player_speed);
|
text.value = format!("{:.0} m/s", player_speed_2d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue