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

Conversation

Jondolf
Copy link
Owner

@Jondolf Jondolf commented Sep 17, 2023

Fixes #93, #108, #158 and mostly fixes #2.

Objective

Currently, trimeshes and compound colliders use the old single contact point approach, which is often quite unstable and causes positional drift. In addition, compound colliders "explode" very easily when they are off-center.

Solution

I found that the penetration depth for contact manifolds seems to be computed incorrectly. It is relative to the center of mass and not the position of each body, so for off-center colliders, it's adding the centers of mass to the contact positions, which results in an incorrect penetration depth. Fixing this makes it possible to use contact manifolds for all collider types and compute the penetration depth manually at the start of each constraint solve.

I also noticed that contact positions for Parry's compound colliders are relative to each subshape, not the entire collider itself. Transforming the contact positions by the subshape positions fixes the issues.

Unsolved issues

Pretty much all colliders seem to be stable now, but convex hulls can sometimes have very weird collision issues in edge cases where the individual faces are large.

2023-09-17.13-14-09.mp4

Sometimes colliders pass through the ground, vanish or explode, and they often bump into the edges. The problems are epecially prevalent near edges.

The contact normals and contact points seem to be computed incorrectly for convex polyhedra sometimes. This is an issue in parry, as it also affects rapier, so I opened an issue here: dimforge/parry#166

As this seems to be an issue in parry and not bevy_xpbd, and it's only an issue in quite specific situations, I'm fine with merging this PR as it fixes a lot of much more common issues.

@Jondolf Jondolf added bugfix A-Collision Relates to the broad phase, narrow phase, colliders, or other collision functionality A-Dynamics Relates to rigid body dynamics: motion, mass, constraint solving, joints, CCD, and so on labels Sep 17, 2023
@Jondolf Jondolf linked an issue Sep 17, 2023 that may be closed by this pull request
@datael datael mentioned this pull request Sep 17, 2023
@Jondolf Jondolf marked this pull request as ready for review September 23, 2023 10:13
@Jondolf Jondolf merged commit cbb043f into main Sep 23, 2023
3 checks passed
@Jondolf Jondolf deleted the contact-stability branch September 23, 2023 14:10
@Jondolf Jondolf mentioned this pull request Sep 23, 2023
RJ pushed a commit to RJ/avian that referenced this pull request Sep 25, 2023
@Jondolf Jondolf added C-Bug Something isn't working and removed bugfix labels Jul 19, 2024
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 A-Dynamics Relates to rigid body dynamics: motion, mass, constraint solving, joints, CCD, and so on C-Bug Something isn't working
Projects
None yet
1 participant