bevy_xpbd
bevy_xpbd copied to clipboard
`Contact`s `is_sensor` field returns true for non-sensor entities
I have an entity with multiple colliders as children - one "real" collider, and some sensors. As soon as my real collider collides with another collider (which also isn't a sensor), the is_sensor field in Contact is true (https://docs.rs/avian3d/latest/avian3d/collision/struct.Contacts.html#structfield.is_sensor) which isn't correct.
I also validated it with a Query<Has<Sensor>> for both - the entity1 and entity2 fields in the Contact struct. The query also returns false for both entities. I can't imagine that this behavior is intentional?
I use the latest release version 0.2.1.
The condition seems incorrect to me:
let mut contacts = Contacts {
entity1: collider1.entity,
entity2: collider2.entity,
body_entity1: collider1.parent.map(|p| p.get()),
body_entity2: collider2.parent.map(|p| p.get()),
during_current_frame: true,
during_previous_frame: previous_contacts.is_some_and(|c| c.during_previous_frame),
manifolds,
is_sensor: collider1.is_sensor
|| collider2.is_sensor
|| !collider1.is_rb
|| !collider2.is_rb,
total_normal_impulse: 0.0,
total_tangent_impulse: default(),
}
Indeed, none of my colliders is a rigid body, but both have a ColliderParent, which is a rigid body. I would expect it to be
is_sensor: collider1.is_sensor || collider2.is_sensor
What is the reason to check for rb?
Maybe we should introduce a is_rigid_body field with
is_rigid_body: collider1.is_rb || collider2.is_rb
Anyone who wants the current behavior could simply do is_sensor || is_rigid_body - but it would be a breaking change.
I just ran into this myself.