Zero out velocity when Speed component is removed.

This commit is contained in:
Nolan Darilek 2021-08-18 14:35:58 -05:00
parent 056a96f7fc
commit 60ad00276e

View File

@ -202,6 +202,14 @@ fn speak_direction(
Ok(())
}
fn remove_speed(removed: RemovedComponents<Speed>, mut query: Query<&mut RigidBodyVelocity>) {
for entity in removed.iter() {
if let Ok(mut velocity) = query.get_mut(entity) {
velocity.linvel = Vec2::ZERO.into();
}
}
}
#[derive(Clone, Debug)]
pub struct NavigationConfig<S, A> {
pub action_backward: Option<A>,
@ -264,7 +272,8 @@ where
.register_type::<RotationSpeed>()
.register_type::<Sprinting>()
.add_system(update_direction.system())
.add_system(speak_direction.system().chain(error_handler.system()));
.add_system(speak_direction.system().chain(error_handler.system()))
.add_system_to_stage(CoreStage::PostUpdate, remove_speed.system());
if config.movement_control_states.is_empty() {
app.add_system(movement_controls::<S, A>.system());
} else {