rapier icon indicating copy to clipboard operation
rapier copied to clipboard

MOTOR joint BUG: NaN body tranlation and rotation when using joint.configureMotorPosition with base body rotation

Open arkonsolutions opened this issue 5 months ago • 1 comments

Hello,

I found a strange behavior when calling configureMotorPosition. It manifests itself precisely when the base body rotates. I rotate the yellow cylinder, and a hammer is attached to it through the revolute joint. I set the joint position via configureMotorPosition(Math.PI, 10000, 100.0). Experimentally, I found out that for revolute joint Math.PI is the highest point. As a result, after the rotation, the world translates the hammer into NaN;NaN;NaN.

VIDEO: https://youtu.be/ap4vPCsgFXE Jointed body DISAPEARED because NaN translation. This happened not every time when you stop rotation and waitm couple seconds.

DEMO: https://pn5j6z.csb.app/
Try to rotate some degree and stop several times. It is not known exactly which time it will manifest itself. In the video above, I captured this moment.

With respect, Sergey

arkonsolutions avatar Jul 15 '25 00:07 arkonsolutions

Hey,

I think I'm experiencing a similar issue with the revolute joint and configureMotorPosition. In my case the whole simulation breaks with an exception Uncaught RuntimeError: unreachable. The bodies seem to be removed just before the crash as there's enough time for threejs to render the scene without them. I guess the next physics step is when it crashes.

I've noticed that it only seems to fail when I let it fully settle in the desired position. A lot of the time it won't due to friction or other objects being in the way, but if it's allowed to settle it crashes out :(

This is how it's set up:

const jointData = JointData.revolute(
      { x: 0, y: -0.4, z: -0.1 },
      { x: 0, y: 0, z: 1 },
      { x: 0, y: 1, z: 0 }
);

joint = world.createImpulseJoint(jointData, body1, body2, true);
(joint as RevoluteImpulseJoint).configureMotorPosition(0, 999, 1);

Edit: One other things I just realised is that this only started happening after updating one of the bodies to rotate using body.applyTorqueImpulse rather than body.setRotation on user input. I undid that change and the motor joint issue isn't there. In terms of how the joint reacts, rotating using setRotation vs applyTorqueImpulse has a very similar effect on how the joint behaves, at least visually. Strange that this change would make a difference.

Extra edit: Seems like my problem was to do with applying tiny amounts of torque impulse. I was continuously applying torque to one of the bodies to keep it facing in a specific direction based on input so when it was already facing the right directing, the angle it was off by would be tiny so only a tiny amount of torque impulse would be applied. Putting a check like if (angle > 0.000001) { around the torque application function seems to fix it for me. Weird.

Thanks.

ChairmanWill avatar Aug 11 '25 20:08 ChairmanWill