Skip to content

Commit

Permalink
Merge pull request #408 from Aceeri/colliders-method
Browse files Browse the repository at this point in the history
RapierContext::colliders convenience method
  • Loading branch information
sebcrozet authored Aug 6, 2023
2 parents af5ac6e + ff2edd8 commit d289865
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Unreleased
### Added
- Add `RapierContext::rigid_body_colliders` to retrieve all collider entities attached to this rigid-body.

## 0.22.0 (10 July 2023)
### Modified
- Update to Bevy 0.11.
Expand Down
15 changes: 15 additions & 0 deletions src/plugin/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,21 @@ impl RapierContext {
.and_then(|h| self.rigid_body_entity(h))
}

/// If entity is a rigid-body, this returns the collider `Entity`s attached
/// to that rigid-body.
pub fn rigid_body_colliders(&self, entity: Entity) -> impl Iterator<Item = Entity> + '_ {
self.entity2body()
.get(&entity)
.and_then(|handle| self.bodies.get(*handle))
.map(|body| {
body.colliders()
.iter()
.filter_map(|handle| self.collider_entity(*handle))
})
.into_iter()
.flatten()
}

/// Retrieve the Bevy entity the given Rapier collider (identified by its handle) is attached.
pub fn collider_entity(&self, handle: ColliderHandle) -> Option<Entity> {
Self::collider_entity_with_set(&self.colliders, handle)
Expand Down

0 comments on commit d289865

Please sign in to comment.