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

Rotated cylinder RevoluteJoint gives entire joint strange rotation #569

Open
rparrett opened this issue Jul 22, 2024 · 3 comments
Open

Rotated cylinder RevoluteJoint gives entire joint strange rotation #569

rparrett opened this issue Jul 22, 2024 · 3 comments

Comments

@rparrett
Copy link
Contributor

rparrett commented Jul 22, 2024

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:

  • A cuboid
  • A rotated cylinder
  • A joint

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

onewheel.mp4

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
Copy link
Contributor

Vrixyz commented Jul 23, 2024

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
Copy link
Contributor Author

rparrett commented Jul 23, 2024

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
Copy link

0x2a-42 commented Jul 23, 2024

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();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants