dimforge / dimforge/bevy_rapier

KinematicCharacterController filter groups don't seem to filter collisions with Dynamic RigidBodies

Open
#400 2 comments 1 reaction 0 assignees View on GitHub
A-Dynamics A-Integration C-Bug D-Medium dependencies P-High S-not-started
Dominant language
Rust
Stars
1.6k
Forks
282
PR merge metrics
No merged PRs in 30d

Description

I seem to be having an issue getting the `KinematicCharacterController` filter groups to work correctly. My setup is that I have a player character modeled by a position-based controller and some projectiles modeled by a dynamic rigid body. I've place both in different groups, but they still show up in the collision detection system. I've also tried ignoring all dynamic bodies using `KinematicCharacterController::filter_flags` but that doesn't seem to work either. Any help or hints are appreciated.

Cargo.toml
```
[dependencies]
bevy = { version = "0.10.1" }
bevy_rapier2d = { version = "0.21.0" }
flamegraph = "0.6.2"
rand = "0.8.5"

[workspace]
resolver = "2"
```

Player:
```
.insert(RigidBody::KinematicPositionBased)
.insert(Collider::cuboid(16., 16.))
.insert(KinematicCharacterController {
translation: Some(Vec2::new(0., 0.)),
filter_groups: Some(CollisionGroups::new(Group::GROUP_2, Group::GROUP_2)),
..default()
});
```

Projectiles:
```
.insert(RigidBody::Dynamic)
.insert(Collider::cuboid(8., 8.))
.insert(CollisionGroups::new(
Group::GROUP_3,
Group::GROUP_3,
))
.insert(Transform::from_xyz(
firing_event.starting_position.x,
firing_event.starting_position.y,
0.,
))
.insert(LockedAxes::ROTATION_LOCKED)
.insert(Velocity {
linvel: Vec2::new(
firing_event.direction.x * firing_event.speed.0,
firing_event.direction.y * firing_event.speed.0,
),
angvel: 0.0,
})
.insert(GravityScale(0.0));
```

Collision detection system:
```
pub fn player_contact_detection_system(
rapier_context: Res,
query: Query>,
) {
let player = query.get_single();
if let Ok(player_entity) = player {
for contact_pair in rapier_context.contacts_with(player_entity) {
let player_collider = if contact_pair.collider1() == player_entity {
contact_pair.collider1()
} else {
contact_pair.collider2()
};
let other_collider: Entity = if contact_pair.collider1() == player_entity {
contact_pair.collider2()
} else {
contact_pair.collider1()
};

println!(
"player contact graph between player collider: {:?}, other collider: {:?}",
player_collider, other_collider
);
}
}
}
```

Output:
```
player contact graph between player collider: 1v0, other collider: 11v0
player contact graph between player collider: 1v0, other collider: 12v0
player contact graph between player collider: 1v0, other collider: 13v0
player contact graph between player collider: 1v0, other collider: 14v0
...
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.