dimforge / rapier

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

Simple pendelum explodes #86

Closed emilk closed 3 years ago

emilk commented 3 years ago

Hello!

I tried setting up capsule as a pendulum like so:

let world_body = bodies.insert(RigidBodyBuilder::new_static().build());
let pendelum_body = bodies.insert(RigidBodyBuilder::new_dynamic().build());

// let half_length = 0.5; // this is fine!
let half_length = 1.0; // this explodes!
let capsule = ColliderBuilder::capsule_x(half_length, 0.5).build();
colliders.insert(capsule, pendelum_body, &mut bodies);

let ball_joint = BallJoint::new(
    [half_length, 0.0, 0.0].into(),
    [half_length, 0.0, 0.0].into(),
);
let joint = JointParams::BallJoint(ball_joint);
joints.insert(&mut bodies, world_body, body, joint);

As the code explains it works great when the pendulum is short, but as soon as it gets longer it explodes almost immediately (i.e. diverges to infinity).

I am using the latest rapier3d = "0.4" with default everything.

sebcrozet commented 3 years ago

Hi!

This is a bug I can reproduce. The problem comes from an error in the 3D ball constraint formulation which will result in the simulation breaking if a rigid-body has a non-uniform local inertia (that's why this same demo works fine with a ball shape instead of a capsule).

This will be fixed in the next release of Rapier.

emilk commented 3 years ago

Awesome, thanks for the quick response!