I have a problem with HingeJoint in the bullet physics implementation (v.3.2.1-stable-sdk1, jme-bullet-native lib).
If I create a hinge joint with a rotation axis that is a unit vector (e.g. Vector3f.UNIT_X) everything works as expected.
But if the axis is even slightly off (like Vector3f( 0.99f, 0, 0.01f ).normalize()), the joint has no effect so that the attached non-static rigid body just falls down.
Am I missing something? Could this be a bug?
Slightly related: How do I revert back to the non-native bullet lib to check if the problem still occurs? If I remove “jme-bullet-native” from my projects libraries, do clean and build, then the console output still says “Bullet-Native: Initializing java classes”
Oops, the code snippet in my previous post somehow got shrunk down to zero pixels
So here it is:
// This works, rigid body revolutes around x axis
axis = Vector3f.UNIT_X;
// This does not work! Body should rotate around an axis slightly off the global x axis.
axis = new Vector3f( 0.99f, 0, 0.01f );
physicsJoint = new HingeJoint
rigidBodyPosA, // Rigid Body A is static (mass = 0)
rigidBodyPosB, // Rigid Body B is dynamic (mass > 0)
jointPos.subtract( rigidBodyPosA ),
jointPos.subtract( rigidBodyPosB ),
physicsSpace.add( physicsJoint );
There is actually more stuff involved, but I edited the code for clarity. If required I may put together a stand-alone example soon.
What happens on my machine if I run the code with a non-unit axis (e.g. UNIT_X) is that the dynamic body behaves as if there was no joint at all.
In the case of your models, the question is “what is center” - and what you define as center in your model, and I believe the correct position of center in your model is the point of its rotation. For a person it would be the bottom of their feet in the middle. For a wheel it would be the middle of the wheel. For a hinge it would be at the hinges rotational axis. For a tree, maybe just above the root center, so scaling would work well, too, when I position it.
Now when I rotate it along its desired axis, it behaves as one expects.