From 7e6fd923a3d42c8d5b355e63495bb12dea29246d Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Thu, 12 May 2022 10:07:38 -0500 Subject: [PATCH] More accurately sync speed and velocity. --- src/navigation.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/navigation.rs b/src/navigation.rs index f334d69..c59b284 100644 --- a/src/navigation.rs +++ b/src/navigation.rs @@ -297,6 +297,15 @@ fn speak_direction( Ok(()) } +fn add_speed(mut commands: Commands, query: Query, Without)>) { + for entity in query.iter() { + commands.entity(entity).insert(Velocity { + linvel: Vec2::ZERO, + ..default() + }); + } +} + fn remove_speed(removed: RemovedComponents, mut query: Query<&mut Velocity>) { for entity in removed.iter() { if let Ok(mut velocity) = query.get_mut(entity) { @@ -377,6 +386,7 @@ where .register_type::() .add_system(update_direction) .add_system(speak_direction.chain(error_handler)) + .add_system(add_speed) .add_system_to_stage(CoreStage::PostUpdate, remove_speed); const MOVEMENT_CONTROLS: &str = "MOVEMENT_CONTROLS"; if config.movement_control_states.is_empty() {