[SOLVED] Trying to get a door working with hinges

So I’m trying to get a door to work correctly using physics (Minie) and it almost works but it’s not very stable again. i.e. it seems possible to almost pull the door out of its hinges (note that I’m using another New6Dof to grab the door). Here is the code:

private fun createHinge(gob: DtGob, game: Game) {
    val joint = New6Dof(gob.control, Vector3f.ZERO, Vector3f(gob.position.x, gob.position.y, gob.position.z),
        Matrix3f.IDENTITY, Matrix3f.IDENTITY, RotationOrder.XYZ
    ).also {
    gob.joint = joint
    val joint2 = New6Dof(gob.control, Vector3f.ZERO, Vector3f(gob.position.x, gob.position.y+2, gob.position.z),
        Matrix3f.IDENTITY, Matrix3f.IDENTITY, RotationOrder.XYZ
    ).also {
    gob.joint2 = joint2

private fun setDoorHingeLimits(it: New6Dof) {
    it.setStiffness(3, 0.1f, true)
    it.setStiffness(4, 0.1f, true)
    it.setStiffness(5, 0.1f, true)
    it.set(MotorParam.LowerLimit, 0, 0f)
    it.set(MotorParam.UpperLimit, 0, 0f)
    it.set(MotorParam.LowerLimit, 1, 0f)
    it.set(MotorParam.UpperLimit, 1, 0f)
    it.set(MotorParam.LowerLimit, 2, 0f)
    it.set(MotorParam.UpperLimit, 2, 0f)
    it.set(MotorParam.LowerLimit, 3, 0f)
    it.set(MotorParam.UpperLimit, 3, 0f)
    it.set(MotorParam.LowerLimit, 4, 0f)
    it.set(MotorParam.UpperLimit, 4, 2f)
    it.set(MotorParam.LowerLimit, 5, 0f)
    it.set(MotorParam.UpperLimit, 5, 0f)

So I’m basically using two hinges. With one it was even worse. So what’s the best way to get this working in a stable way? Thanks

1 Like

One of the hard parts about using a joint as the hand with an absolute location is that it’s trivial for the user to create situations that are impossible for the physics engine to resolve.

For example, if you use a spring between the hand and the knob instead, it probably works “fine”… in the constraints sense. Though you will get some bouncing back and forth (the spring) in exchange for that.

I actually suspected something like that. But for the door it’s fine? i.e. two hinges of the New6Dof type? Or is there a better way to set this up?

I don’t know enough about bullet internals to say for sure.

…but having written my own physics engine and playing with joint constraints, a hinge joint (specific to one axis rotation) is way simpler to implement than a 6dof joint and in general the hinge joint is bound to be more stable.

If bullet has this sort of hinge joint then you should try it.

1 Like

One trick I’ve discovered for using New6Dof with locked rotation axes is to enable the spring for each locked axis. In Java:

            RotationMotor rotMotor = new6dof.getRotationMotor(axisIndex);
            int rotDofIndex = axisIndex + 3;
            new6dof.set(MotorParam.UpperLimit, rotDofIndex, 0f);
            new6dof.set(MotorParam.LowerLimit, rotDofIndex, 0f);

Enabling springs seems to make axis locking much more effective. I don’t understand why.

I just tried with a normal HingeJoint and it works MUCH better. Thanks for the advice