bevy_rapier
bevy_rapier copied to clipboard
Feature request: ContactPairView::other_collider
Hi!
In the documentation I saw this example:
let other_collider = if contact_pair.collider1() == entity {
contact_pair.collider2()
} else {
contact_pair.collider1()
};
I thought that I'd suggest a method on ContactPairView; other_collider
Disclaimer: I'm just learning rust so this might be bad code. I'd appreciate any feedback.
Anyway, here's the idea code:
impl<'a> ContactPairView<'a> {
...
pub fn other_collider(&self, entity: Entity) -> Option<Entity> {
if entity == self.collider1() { return Some(self.collider2()); };
if entity == self.collider2() { return Some(self.collider1()); };
None
}
}
Thoughts? :)
Hi! I transferred this issue to the bevy_rapier repository.
I believe this is a good addition. Please, feel free to open a PR. I suggest the implementation to look like this (return isn’t really idiomatic in Rust):
pub fn other_collider(&self, entity: Entity) -> Option<Entity> {
if entity == self.collider1() { Some(self.collider2()) }
else if entity == self.collider2() { Some(self.collider1()) }
else { None }
}
(cargot fmt will take care of formatting this properly).
Would bevy_rapier2d::geometry::CollidingEntities component work for you?
https://docs.rs/bevy_rapier2d/latest/bevy_rapier2d/geometry/struct.CollidingEntities.html