[SOLVED] Moving a HingeJoint

Hi,

So I have 2 boxes (a blue and a purple one). The purple is connected with the blue by a HingeJoint.
Im moving the blue box by using setPhysicsLocation() on the blue box node.
When I move it at a higher speed the joint gets a offset. (so its not really connected anymore)
Video of the problem: https://vimeo.com/424369531

—init—

holderNode=PhysocsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f( .1f, .1f, .1f)),0);
    holderNode.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f,-10,0f));
    rootNode.attachChild(holderNode);
    getPhysicsSpace().add(holderNode);

hammerNode=PhysocsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f( .3f, .3f, .3f)),1);
    hammerNode.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f,-11,0f));
    hammerNode.getControl(RigidBodyControl.class).setDamping(0.4f, 0);
    hammerNode.getControl(RigidBodyControl.class).setMass(3f);
    rootNode.attachChild(hammerNode);
    getPhysicsSpace().add(hammerNode);

joint=new HingeJoint(holderNode.getControl(RigidBodyControl.class), hammerNode.getControl(RigidBodyControl.class), Vector3f.ZERO, new Vector3f(0f,-1,0f), Vector3f.UNIT_Z, Vector3f.UNIT_Z);
    getPhysicsSpace().add(joint);

—update—

public void simpleUpdate(float tpf) {

    Vector3f center = new Vector3f(0,0,0);
    Vector2f vector = circle(center, 10, angle);
    //holderNode.move(new Vector3f(0,0.1f,0));
    holderNode.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(vector.x,vector.y,0));

    
    angle+=speed;
    
}

~Thx

1 Like

Welcome to the JMonkeyEngine community.

I believe it’s normal for dynamic bodies to lag one timestep behind kinematic ones. To minimize the resulting discrepancies, try reducing the time step. For instance:

    getPhysicsSpace().setAccuracy(0.001f);
2 Likes

U’r my hero, thanks!!

1 Like