bevy_xpbd icon indicating copy to clipboard operation
bevy_xpbd copied to clipboard

`Contact`s `is_sensor` field returns true for non-sensor entities

Open morgenthum opened this issue 8 months ago • 3 comments
trafficstars

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.

morgenthum avatar Mar 02 '25 14:03 morgenthum

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?

morgenthum avatar Mar 02 '25 14:03 morgenthum

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.

morgenthum avatar Mar 02 '25 14:03 morgenthum

I just ran into this myself.

alec-deason avatar Mar 18 '25 21:03 alec-deason