dimforge / rapier

2D and 3D physics engines focused on performance.
https://rapier.rs
Apache License 2.0
3.96k stars 249 forks source link

Friction impulse not applied at contact point with additional_mass #666

Open andrewbaxter opened 3 months ago

andrewbaxter commented 3 months ago

In this example:

    let ground_height = 0.1;
    colliders.insert_with_parent(
        ColliderBuilder::cuboid(100.1, ground_height, 100.1).friction(0.5),
        bodies.insert(RigidBodyBuilder::fixed().translation(vector![0.0, -ground_height, 0.0])),
        &mut bodies,
    );
    colliders.insert_with_parent(
        ColliderBuilder::cuboid(0.2, 5., 1.5).friction(0.5).mass(0.),
        bodies.insert(
            RigidBodyBuilder::dynamic()
                .additional_mass(0.5)
                .translation(vector![-10., 6.0, 0.0])
                .linvel(vector![20., 0., 0.])
                .can_sleep(false),
        ),
        &mut bodies,
    );

A tall, narrow cuboid moving quickly horizontally falls onto the ground. If the collider has mass and the rigid body doen't, when the cuboid contacts the ground it starts toppling over as the top maintains momentum but the bottom near the contact point slows down. When adding the mass to the rigid body instead of the collider the body simply slides along the ground without tipping over.

This is unexpected, and I can't think of any reason why this behavior would be intentional. If it is intentional though, it'd be good to have visible documentation. I looked in the Friction section first, because I thought maybe there was some parameter about how friction forces are applied (at body center or at point of contact).

Vrixyz commented 2 months ago

Reproduction code: https://github.com/Vrixyz/rapier/pull/1

With collider mass at 0.5 and rigidbody additional mass at 0.0, here is the current behaviour, which is expected:

https://github.com/user-attachments/assets/0880b1e7-af6b-4712-8834-7657fa228422

With collider mass at 0.0 and rigidbody additional mass at 0.5, here is the current behaviour, which is unexpected:

https://github.com/user-attachments/assets/e062d7cb-83d1-4a11-a842-cdb89c832887