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

Partial sensor entities #193

Closed
umut-sahin opened this issue Oct 22, 2023 · 2 comments
Closed

Partial sensor entities #193

umut-sahin opened this issue Oct 22, 2023 · 2 comments
Labels
A-Collision Relates to the broad phase, narrow phase, colliders, or other collision functionality question Further information is requested

Comments

@umut-sahin
Copy link

Hi, thanks for the amazing library!

Here is my use case:

  • I want the player to trigger collision response against walls.
  • I don't want the player to trigger collision response against enemies.
  • I want the player to trigger collision events with enemies.

Which means the player needs to be a regular physics object against walls, but sensor against enemies.

Right now, I'm spawning two entities for the player, one for physical collisions and one for sensor collisions, but these need to be synced with each other at some point. I'm doing that in the update. I'm sure this will cause problems as they might get out of sync within the physics world.

Is there a better way to achieve this?

@Jondolf Jondolf added question Further information is requested A-Collision Relates to the broad phase, narrow phase, colliders, or other collision functionality labels Oct 22, 2023
@Jondolf
Copy link
Owner

Jondolf commented Oct 22, 2023

On the main branch (and soon 0.3), one approach would be to use child colliders (#154) which were just merged.

You could give the player a normal collider with collision layers to avoid collision response against enemies, and add a child collider as a sensor that can trigger collision events for all layers. Roughly like this:

commands.spawn((
    RigidBody::Dynamic,
    Collider::capsule(1.0, 0.4),
    CollisionLayers::new([Layer::Player], [Layer::Environment]),
))
.with_children(|child_builder| {
    child_builder.spawn((
        Collider::capsule(1.0, 0.4), // or whatever shape you want
        Sensor,
    ));
});

Child colliders should be automatically synced properly.

@umut-sahin
Copy link
Author

That's exactly what I was looking for! Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Collision Relates to the broad phase, narrow phase, colliders, or other collision functionality question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants