dimforge / bevy_rapier

Official Rapier plugin for the Bevy game engine.
https://rapier.rs
Apache License 2.0
1.26k stars 259 forks source link

Rotated cylinder RevoluteJoint gives entire joint strange rotation #569

Open rparrett opened 3 months ago

rparrett commented 3 months ago

I am attempting to work around #457 and encountered what I think may be a separate bug. I suspect it might be a separate bug because there are no non-default transforms involved in this repro.

Here's a super simple little playground with a vehicle approximating a "onewheel", consisting of:

https://github.com/rparrett/rapier_wheel_nonsense/blob/e22e10a22183209c1821979b62fc03bfe699e0d9/src/main.rs

https://github.com/user-attachments/assets/ed056282-ded2-440c-bef0-015ca305d788

The only rotation in the code is this line:

joint.set_local_basis2(Quat::from_rotation_z(std::f32::consts::FRAC_PI_2));

So the 15 degree rotation seems quite odd.

Vrixyz commented 3 months ago

~it looks like 45 degrees to me ? which frac_pi_2 would make sense for: (pi / 2 radian = 1/4 turn = 45 degrees).~

Alright 🤦 yep seems weird

rparrett commented 3 months ago

When I run the code on my machine, I see a rotation of

0.5337742 radians, or ~30 degrees. (FRAC_PI_2 would be 1.5707964 radians or 90 degrees).

Side view:

image
0x2a-42 commented 3 months ago

It seems to work if a MultibodyJoint is used instead of an ImpulseJoint.

    let mut joint = RevoluteJointBuilder::new(Vec3::X)
        .local_anchor1(Vec3::ZERO)
        .local_anchor2(Vec3::ZERO)
        .build();
    joint.set_contacts_enabled(false);
    joint.data.set_local_basis2(Quat::from_rotation_z(std::f32::consts::FRAC_PI_2));

    let wheel = commands
        .spawn((
            Name::new("WheelCollider"),
            RigidBody::Dynamic,
            Collider::cylinder(0.4, 0.8),
            MultibodyJoint::new(bike, joint.into()),
        ))
        .id();