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 solver contact normal for rotated child colliders #409

Merged
merged 1 commit into from
Jul 9, 2024
Merged
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
13 changes: 9 additions & 4 deletions src/dynamics/solver/contact/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,14 @@ impl ContactConstraint {
let collision_margin: Scalar = collision_margin.into().0;
let speculative_margin: Scalar = speculative_margin.into().0;

let normal = *body1.rotation * manifold.normal1;
// Local-space outward contact normal on the first body.
// The normal is transformed from collider-space to body-space.
let local_normal1 = collider_transform1.map_or(manifold.normal1, |transform| {
transform.rotation * manifold.normal1
});

// The world-space normal used for the contact solve.
let normal = *body1.rotation * local_normal1;

// TODO: Cache these?
// TODO: How should we properly take the locked axes into account for the mass here?
Expand All @@ -126,14 +133,12 @@ impl ContactConstraint {
constraint.tangent_directions(body1.linear_velocity.0, body2.linear_velocity.0);

for mut contact in manifold.contacts.iter().copied() {
// Transform contact data from collider-space to body-space.
// Transform contact points from collider-space to body-space.
if let Some(transform) = collider_transform1 {
contact.point1 = transform.rotation * contact.point1 + transform.translation;
contact.normal1 = transform.rotation * contact.normal1;
}
if let Some(transform) = collider_transform2 {
contact.point2 = transform.rotation * contact.point2 + transform.translation;
contact.normal2 = transform.rotation * contact.normal2;
}

contact.penetration += collision_margin;
Expand Down