Odd joint constraint behaviour

I have three scenes where I am testing a hinge joint script. In the scene that is a copy of the original project, the script works just fine. In both scenes I have created, the script bugs out like crazy and I have no idea what the difference is between the two that don’t work and the one that does.
Working scene: https://launch.playcanvas.com/596420?debug=true (it’s a little buggy at first, but it fixes itself and works fine after)
Broken scenes: https://launch.playcanvas.com/596414?debug=true (two capsules, like the first scene), https://launch.playcanvas.com/593574?debug=true (scene using the models I want to use this script with)

Project links: https://playcanvas.com/editor/scene/596420 (working scene), https://playcanvas.com/editor/scene/593574 (other two scenes in this project, collisionTest3 and hinge scene)

Tried using the script from the first scene in the third scene, and problem sort of solved (again no difference in the scripts as far as I can see). The models connect in the way they’re supposed to, but the bottom one falls a fair distance before the joint stops it.
Hinge.js and HingeConstraint.js: https://playcanvas.com/editor/code/532971?tabs=11402284,11566143

EDIT: Found the problem, but not sure what is causing it.

var offsetB = new pc.Vec3();
    var matrixB = this.partB.getWorldTransform().clone();
    console.log(this.partB.worldTransform);
    matrixB.invert();
    console.log(matrixB);
    matrixB.transformPoint(this.entity.getPosition(), offsetB);

Somewhere and somehow between getting the world transform matrix and inverting it, the matrix changes. This happens both with the original script and mine in the scene below. The difference being my script makes the second part go above the first, while the original does the opposite (like it’s supposed to), but it goes too far.

Opening the debug console here will display the matrices.

Got the joint working properly. Now to just get the model rotating around the joints axis instead of its own.
Removed second part from the hinge script:

var HingeSingle = pc.createScript('hingeSingle');


HingeSingle.attributes.add('Part', {type: 'entity'});
HingeSingle.attributes.add('limits', {type: 'vec2'});

HingeSingle.attributes.add('partOffset', {type: 'vec3'});

HingeSingle.attributes.add('disableCollision', {type: 'boolean', default: false});
HingeSingle.attributes.add('debugDraw', {type: 'boolean', default: false});

HingeSingle.prototype.initialize = function()
{
    this.createJoint();
    this.white = new pc.Color(1,1,1,1);
    this.temp = new pc.Vec3();
    
    this.on('attr:limits', function (calue, prev) 
    {
        this.joint.setLimit(value.x * pc.math.DEG_TO_RAD, value.y * pc.math.DEG_TO_RAD, 0.9, 0.3, 1);
    });
};

HingeSingle.prototype.draw = function()
{
    this.app.renderLine(this.Part.getPosition(), this.entity.getPosition(), this.white);
};

HingeSingle.prototype.update = function(dt)
{
    if(this.debugDraw)
    {
        this.draw();
    }
};

HingeSingle.prototype.createJoint = function()
{
    var rb = this.Part.rigidbody.body;
    
    var offset = new pc.Vec3();
    var matrix = this.Part.getWorldTransform().clone();
    console.log("Matrix: " + matrix);
    console.log("World Transform: " + this.Part.worldTransform);
    matrix.invert();
    console.log("Inverse Matrix: " + matrix);
    matrix.transformPoint(this.entity.getPosition(), offset);
    
    var local = new Ammo.btTransform();
    
    local.setIdentity();
    
    var orient = this.partOffset;
    
    local.getBasis().setEulerZYX(orient.x * pc.math.DEG_TO_RAD, orient.y * pc.math.DEG_TO_RAD, orient.z * pc.math.DEG_TO_RAD);
    local.setOrigin(new Ammo.btVector3(offset.x, offset.y, offset.z));
    
    this.joint = new Ammo.btHingeConstraint(rb, local);
    
    this.joint.setLimit(this.limits.x * pc.math.DEG_TO_RAD, this.limits.y * pc.math.DEG_TO_RAD, 0.9, 0.3, 1);
    
    this.app.systems.rigidbody.dynamicsWorld.addConstraint(this.joint, this.disableCollision);
};

NOTE: Links may not work as I had to delete the projects to free up some space.