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

Fix contact stability for non-convex colliders #156

Merged
merged 6 commits into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions crates/bevy_xpbd_3d/examples/basic_kinematic_character.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,15 @@ fn movement(

fn kinematic_collision(
collisions: Res<Collisions>,
mut bodies: Query<(&RigidBody, &mut Position)>,
mut bodies: Query<(&RigidBody, &mut Position, &Rotation)>,
) {
// Iterate through collisions and move the kinematic body to resolve penetration
for contacts in collisions.iter() {
// If the collision didn't happen during this substep, skip the collision
if !contacts.during_current_substep {
continue;
}
if let Ok([(rb1, mut position1), (rb2, mut position2)]) =
if let Ok([(rb1, mut position1, rotation1), (rb2, mut position2, _)]) =
bodies.get_many_mut([contacts.entity1, contacts.entity2])
{
for manifold in contacts.manifolds.iter() {
Expand All @@ -146,9 +146,9 @@ fn kinematic_collision(
continue;
}
if rb1.is_kinematic() && !rb2.is_kinematic() {
position1.0 -= contact.normal * contact.penetration;
position1.0 -= contact.global_normal1(rotation1) * contact.penetration;
} else if rb2.is_kinematic() && !rb1.is_kinematic() {
position2.0 += contact.normal * contact.penetration;
position2.0 += contact.global_normal1(rotation1) * contact.penetration;
}
}
}
Expand Down
Loading