diff --git a/src/navigation.rs b/src/navigation.rs index c589888..79ff46e 100644 --- a/src/navigation.rs +++ b/src/navigation.rs @@ -58,7 +58,7 @@ fn movement_controls( ), With, >, - exploration_focused: Query<(Entity, &ExplorationFocused)>, + exploration_focused: Query>, ) where S: bevy::ecs::component::Component + Clone + Debug + Eq + Hash, A: Hash + Eq + Clone + Send + Sync, @@ -117,7 +117,7 @@ fn movement_controls( if direction.length_squared() != 0. { commands.entity(entity).remove::(); commands.entity(entity).remove::(); - for (entity, _) in exploration_focused.iter() { + for entity in exploration_focused.iter() { commands.entity(entity).remove::(); } direction = direction.normalize(); @@ -176,16 +176,20 @@ fn movement_controls( fn update_direction( mut commands: Commands, - query: Query< - (Entity, &Transform, Option<&CardinalDirection>), + mut query: Query< + (Entity, &Transform, Option<&mut CardinalDirection>), (With, Changed), >, ) { - for (entity, transform, direction) in query.iter() { + for (entity, transform, direction) in query.iter_mut() { let forward = transform.local_x(); let yaw = Angle::Radians(forward.y.atan2(forward.x)); let new_direction: CardinalDirection = yaw.into(); - if direction != Some(&new_direction) { + if let Some(mut direction) = direction { + if *direction != new_direction { + *direction = new_direction; + } + } else { commands.entity(entity).insert(new_direction); } }