Problem with joints

I’m trying to connect multiple objects via joints.
My goal is that one object copies every change in translation and rotation of the other object, as if they where connected with a stick (not with a rope!)
I connect two objects by pressing “F” on them one after another.

[java]if(connectTemp == null && checkCollisionGeometry().getParent() == removableNode){
//“save” the first klicked object (Method connectBricks() has to be called twice to connect two objects)
connectTemp = checkCollisionGeometry();

}else if(checkCollisionGeometry().getParent() == removableNode){

        //Control of the first klicked Object
            RigidBodyControl a = (RigidBodyControl)connectTemp.getControl(0);
        //Control of the second klicked Object
            RigidBodyControl b = (RigidBodyControl)checkCollisionGeometry().getControl(0);
        //Rotation Matrices of both Objects
            Matrix3f matA = a.getPhysicsRotationMatrix();
            Matrix3f matB = b.getPhysicsRotationMatrix();
        SixDofJoint joint1 = new SixDofJoint(a, b, (b.getPhysicsLocation().subtract(a.getPhysicsLocation())).mult(1f),Vector3f.ZERO, matB, matA, false);
        //preventing any rotation of the joint so that the joint will only act as fixed connection and not as pendulum or something like that
        connectTemp = null;
    }  [/java]

It works fine when the objects aren’t rotated before I connect them, but when the first klicked object or both of the objects are rotated before connecting them, the behavior is strange.

I think the problem has something to do with the rotation Matrices in the constructor of SixDofJoint
SixDofJoint(PhysicsRigidBody nodeA, PhysicsRigidBody nodeB, Vector3f pivotA, Vector3f pivotB, Matrix3f rotA, Matrix3f rotB, boolean useLinearReferenceFrameA)

I hope that anybody can help me :slight_smile:

I uploaded the program for demonstration, read the controls before running it:

Space --> place new brick

lMouse --> select brick for transformation/replace selected brick
MouseWheel —> rotate selected brick
Space --> change rotation axis of selected brick

F --> Select first/second brick for connection
MiddleMouse --> shoot cannonball

I’d combine both objects to one instead of trying to make a joint 100% rigid.

Thanks, that helped alot!

I combine Objects with this small code:
Material mat = new Material(assetManager,

    Box box = new Box(1,1,1);
    Geometry g1 = new Geometry("g1", box);
    Geometry g2 = new Geometry("g2", box);
    Geometry g3 = new Geometry("g3", box);
    g1.move(-4, 0, 0);
    g2.move(0, 0, 0);
    g3.move(2, 0, 1);
    Node boxes = new Node("boxes");
    RigidBodyControl boxesControl = new RigidBodyControl(1f);
    Node optimizedBoxes = (Node) GeometryBatchFactory.optimize(boxes);


Is there any way to get the Geometries I optimized back afterwards?
Would need this for dividing a combined Object multiple times (a piece of wall that gets broken into smaller pieces).

Well I just figured out that the barycenter of the combined object doesn’t get recalculated.
How to do so?

The center of mass is always the center of the geometry or node you attach the RigidBodyControl to. Offset sub-geometry or the mesh to move the center of mass relatively.

Yes but that doesn’t work for complex objects like this one:

Besides the complex objects are created in-game, thus they have random shapes.

So is there another way to get what I’m searching for or should I keep trying to make the joints rigid?

It always works. The center of mass is always where the RigidBody center is, no matter how complex the model. You seem to expect some “automatic center detection”. Its not there, in no case. You always have the center of mass at the center of the object and move the collision shape / mesh accordingly.