Skip to content

Commit

Permalink
Only remove Sleeping if entity has the component
Browse files Browse the repository at this point in the history
To implement the previous commit we added retrieval of whether and entity has a Sleeping component. Since we therefore now already know whether the entity has a Sleeping component, there's no point in trying to remove it if it doesn't
  • Loading branch information
datael committed Sep 7, 2024
1 parent d6e2651 commit 951f09e
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/dynamics/sleeping/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,9 @@ fn wake_on_collision_ended(
|| moved_bodies.get(p.get()).is_ok_and(|pos| pos.is_changed())
})
}) {
commands.entity(entity).remove::<Sleeping>();
if is_sleeping {
commands.entity(entity).remove::<Sleeping>();
}
time_sleeping.0 = 0.0;
}
}
Expand All @@ -301,12 +303,16 @@ fn wake_on_collision_ended(
if contacts.during_current_frame || !contacts.during_previous_frame {
continue;
}
if let Ok((_, mut time_sleeping, _)) = sleeping.get_mut(contacts.entity1) {
commands.entity(contacts.entity1).remove::<Sleeping>();
if let Ok((_, mut time_sleeping, is_sleeping)) = sleeping.get_mut(contacts.entity1) {
if is_sleeping {
commands.entity(contacts.entity1).remove::<Sleeping>();
}
time_sleeping.0 = 0.0;
}
if let Ok((_, mut time_sleeping, _)) = sleeping.get_mut(contacts.entity2) {
commands.entity(contacts.entity2).remove::<Sleeping>();
if let Ok((_, mut time_sleeping, is_sleeping)) = sleeping.get_mut(contacts.entity2) {
if is_sleeping {
commands.entity(contacts.entity2).remove::<Sleeping>();
}
time_sleeping.0 = 0.0;
}
}
Expand Down

0 comments on commit 951f09e

Please sign in to comment.