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

How to simulate triggers between kinematic and sensor bodies #594

Open
fabiopolimeni opened this issue Feb 20, 2024 · 3 comments
Open

How to simulate triggers between kinematic and sensor bodies #594

fabiopolimeni opened this issue Feb 20, 2024 · 3 comments

Comments

@fabiopolimeni
Copy link

fabiopolimeni commented Feb 20, 2024

I have a character controller that is position based an moved like this

let delta = controller.move_shape(
                    dt,
                    &physics.rigid_body_set,
                    &physics.collider_set,
                    &physics.query_pipeline,
                    collider.shape(),
                    &pos.into(),
                    displacement.into(),
                    QueryFilter::new()
                        .exclude_rigid_body(self.rigid_body_handle)
                        .exclude_sensors(),
                    |collision| {
                        collisions.push((
                            self.rigid_body_handle,
                            physics
                                .collider_set
                                .get(collision.handle)
                                .unwrap()
                                .parent()
                                .unwrap(),
                        ));
                    },
                );

What I have to do to ignore the collision against a sensor, is to add the exclude_sensors() from the QueryFilter. Note that the sensor is attached to a fixed rigid body, and according to the documentation, collisions between two non-dynamic rigid bodies, such as the kinematic controller and the fixed body's sensor I have, should never occur. Nevertheless, the character controller is not capable of passing through the sensor, despite being attached to a fixed body.

This would not be a big deal if I could simply ignore sensors with exclude_sensors(), but I still need to receive a collision/intersection event when that happens, essentially to simulate a trigger behaviour. That is not happening with the current configuration I have.

So, my question is, what is the strategy to simulate a trigger behaviour? That is, my character is capable of passing through an object, while still firing some events when I entered/exited the sensor collider. Would I need to use the Intersection Graph? Would I also need to hook up into the solver to modify/ignore contacts? It all seems all a bit more complicated than I expect, I am more inclined to assume I am missing something here, as triggers should not be such a pain to setup. I would appreciated any help thanks.

@fabiopolimeni
Copy link
Author

fabiopolimeni commented Mar 13, 2024

Ok, this is not receiving much love here. Should I repost in Discussions instead? Might me more appropriate?

@sebcrozet
Copy link
Member

Sorry, that issue went under the radar.

The QueryFilter provided to the character controller for the character controller update is fairly independent from the logic driving collision-detection during the main physics pipeline stepping. So you could keep your QueryFilter with exclude_sensors() while updating your character controller to obtain the desired motion ignoring sensors, and at the same time set the active collision types of your character controller’s collider to ActiveCollisionTypes::default() | ActiveCollisionTypes::KINEMATIC_FIXED (or just ActiveCollisionTypes::all()), and its active events to ActiveEvents::COLLISION_EVENTS.

This will enable collision events involving your character controller and your trigger (and other static shapes).

@fabiopolimeni
Copy link
Author

Cool, thank you for the hint, I will give it a try soon ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants