[SOLVED] How to update the Ammo.btHingeConstraint

1.the project editor scene :https://playcanvas.com/editor/scene/607445
2.the game rule is add force by click right arrow button.raycast new pivot point by click mouse button left.
3.the question is:I use the Ammo.js physics Hinge joint,I want to change the Ammo.btVector3 on update . so the player can move by swing.

the key part of code :


 Hinge2.prototype.initialize = function(app) {
    
    var ownerPos = this.entity.getPosition();
    pivotPos = this.linePivot.getPosition();
    var relativeVector3 = new pc.Vec3();
    relativeVector3.sub2(pivotPos,ownerPos);
    
    //console.log(relativeVector3);
    //Physic Joint
    var pivot = new Ammo.btVector3(relativeVector3.x,relativeVector3.y,relativeVector3.z);
    var pcq = new pc.Quat().setFromAxisAngle(pc.Vec3.FORWARD, -90);
    var q = new Ammo.btQuaternion(pcq.x, pcq.y, pcq.z, pcq.w);

    ammoBtT = new Ammo.btTransform();
    ammoBtT.setIdentity();
    ammoBtT.setRotation(q);
    ammoBtT.setOrigin(pivot);

    var joint = new Ammo.btHingeConstraint(this.entity.rigidbody.body, ammoBtT,true);
    joint.setLimit(-Math.PI/2, Math.PI/2, 0.9, 0.3, 1);

    this.app.systems.rigidbody.dynamicsWorld.addConstraint(joint);
        this.app.systems.rigidbody.dynamicsWorld.
    // never sleep
    this.entity.rigidbody.body.setActivationState(pc.RIGIDBODY_DISABLE_DEACTIVATION);
    
    
};


// update code called every frame
Hinge2.prototype.update = function(dt) {
  
    //Set physics
    
};

Please help me the hinge joint update question,more thanks.:slightly_smiling_face:

Erm… I don’t see the question? Which btVector3? Changing the value is easy but what do you want to do with it?

I want to change the linePivot postion in update method,but the Ammo.btHingeConstraint is not run .you could look my playcanvas scene .thanks

I realize your original post is now a year old @Donatello, but in case you find it useful, I recommend checking out this project for a comprehensive implementation of btHingeConstraint for PlayCanvas:

https://playcanvas.com/project/618829

Plus, it implements other constraint types too.

1 Like