[SOLVED] Further progress getting a door to work

So I made some improvements on getting a door to work. It is starting to be ok but I still have some issues as you can see in the linked video. The linked gist contains all code I have so far for this: Physics door test · GitHub

And here is the video: https://www.youtube.com/watch?v=-dY0YGsEprY&ab_channel=JorritTyberghein

Basically the problem is that it works relatively ok while I’m holding the door. As soon as I release the grab though the door starts swinging heavily for a while. I’m not sure how to solve that problem. Any clues are welcome. Thanks!

A couple suggestions:

  • hinge.setCollisionBetweenLinkedBodies(false)
  • increase the damping of the door using doorBody.setDamping(0.5f, 0.5f)

That made no difference I’m afraid. Note that I am initializing all physics objects like this already:

        RigidBodyControl(shape, (flags.mass ?: 0.0f) * 10f).also {
            it.angularDamping = 0.05f
            it.contactDamping = 0.1f
            it.friction = 2f
            it.rollingFriction = 0.03f
            it.spinningFriction = 0.03f
            it.setDamping(0.5f, 0.5f)   // For door
            spatial.addControl(it)
            game.bulletAppState.getPhysicsSpace()?.add(it)
            gob.control = it
        }

So I added the setDamping() as you suggested but it still swings heavily when I release the door. Also I was using an EmptyShape so I think there is already no collision between the handle and the door but I did add the setCollisionBetweenLinkedBodies(false) too.

Also here is how the hinge with the door itself is created:

    gob.joint = HingeJoint(gob.control, Vector3f.ZERO, gob.position.asVector(),
            Vector3f.UNIT_Y, Vector3f.UNIT_Y, JointEnd.A).also {
        val o = FastMath.TWO_PI - gob.orientation.y
        it.setLimit(o, o + FastMath.HALF_PI)
        game.bulletAppState.physicsSpace.add(it)
    }

Hmm I’m getting much more stable (but weird) result if I do something like this instead:

    gob.joint = HingeJoint(gob.control, Vector3f.ZERO, gob.position.asVector(),
            Vector3f.UNIT_Y, Vector3f.UNIT_Y, JointEnd.A).also {
        val o = FastMath.TWO_PI - gob.orientation.y
        it.setLimit(o, o + FastMath.HALF_PI, 0.9f, 1.0f, 0.5f)
        it.isAngularOnly = true
        game.bulletAppState.physicsSpace.add(it)
    }

Basically the door stays where it is if you stop grabbing it but it is possible to grab the door out of its hinge

Seems this hinge displacement is a common problem. I’ve seen it come up on google a lot. But so far I haven’t found a solution yet

If the door hinges are single-ended, then use

doorBody.addToIgnoreList(doorFrameBody);

to tell Bullet to ignore collisions between the door frame and the door. Do the same for the floor, if you have one.

Here’s a working example of a swinging door, in Java:

4 Likes

Thanks a lot, based on the java example as well as some of the other comments I managed to make it work!

4 Likes

Do you have any advice for those facing similar issues?

1 Like

Well basically the clue was adding the doorframe (or geometry that touches the door) to the ignore list of the door. Then the hinge is created as follows:

    gob.joint = HingeJoint(gob.control, Vector3f.ZERO, gob.position.asVector(),
            Vector3f.UNIT_Y, Vector3f.UNIT_Y, JointEnd.B).also {
        val o = FastMath.TWO_PI - gob.orientation.y
        it.setLimit(o, o + FastMath.HALF_PI)
        game.bulletAppState.physicsSpace.add(it)
    }

And that basically does it. After all pretty simple but I never though that the surrounding geometry would be the problem

2 Likes

Any time you can avoid “impossible to solve” situations for the physics engine, it will be happier.

…the trick is in seeing what’s “impossible to solve”.