Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: ContactPairView::other_collider #215

Open
cha0s opened this issue Jul 14, 2022 · 2 comments
Open

Feature request: ContactPairView::other_collider #215

cha0s opened this issue Jul 14, 2022 · 2 comments
Labels
A-Integration very bevy specific C-Enhancement New feature or request D-Easy good first issue Good for newcomers P-Low S-not-started Work has not started

Comments

@cha0s
Copy link

cha0s commented Jul 14, 2022

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? :)

@sebcrozet sebcrozet transferred this issue from dimforge/rapier Jul 17, 2022
@sebcrozet
Copy link
Member

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).

@chungwong
Copy link
Contributor

Would bevy_rapier2d::geometry::CollidingEntities component work for you?
https://docs.rs/bevy_rapier2d/latest/bevy_rapier2d/geometry/struct.CollidingEntities.html

@Vrixyz Vrixyz added C-Enhancement New feature or request D-Easy P-Low S-in-progress A-Integration very bevy specific good first issue Good for newcomers S-not-started Work has not started and removed S-in-progress labels May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Integration very bevy specific C-Enhancement New feature or request D-Easy good first issue Good for newcomers P-Low S-not-started Work has not started
Projects
None yet
Development

No branches or pull requests

4 participants