bevy_xpbd icon indicating copy to clipboard operation
bevy_xpbd copied to clipboard

`RayCaster.ignore_self` doesn't ignore colliders in children

Open johannesvollmer opened this issue 1 year ago • 1 comments
trafficstars

In general, all colliders in children of a rigidbody do contribute to the rigidbody in the parent entity.

Therefore, it would seem sensible to me that RayCaster.ignore_self would have a consistent behaviour, also ignoring all children colliders, not just the entity itself. Or at least offer an analogous alternative, maybe RayCaster.ignore_children. What do you think? I might be able to contribute this.

Current workaround is to manually filter the hits:

let hits = hits.iter().filter(|&hit| is_child_of(hit.entity, rigidbody_parent_entity, &parents));

fn is_child_of(child: Entity, maybe_parent: Entity, parents: Query<&Parent>) -> bool {
    parents.iter_ancestors(child).find(|&parent| parent == maybe_parent).is_some()
}

johannesvollmer avatar Jul 28 '24 12:07 johannesvollmer

Note that the proposed API should probably be called ignore_descendants to mirror how iter_descendants works in Bevy.

janhohenheim avatar Jul 28 '24 22:07 janhohenheim