Moving a bunch of contacting bodies, avoiding instabilities

Post Reply
gsimard
Posts: 4
Joined: Fri Mar 01, 2013 5:20 pm

Moving a bunch of contacting bodies, avoiding instabilities

Post by gsimard »

Hello,

I'm using the java port of Bullet Physics (jBullet) for a game I'm making.

I'm trying to move a bunch of bodies by simply calling body.setCenterOfMassTransform with a transform that has been translated (no rotation here) by the same amount for all bodies.

Problems occur whenever I try to do this for bodies that already had contact points (bodies bounce from each other).

I tried to fix that with this nifty bit of code, to no avail (I thought perhaps the contact point cache needed to be translated as well):

Code: Select all

    public void translateManifolds(CollisionObject colObj, Vector3f dx) {

        Dispatcher dispatcher = getDispatcher();

        // Find all manifold caches associated with this collision object
        int numManifolds = dispatcher.getNumManifolds();
        for (int i = 0 ; i < numManifolds ; i++) {

            PersistentManifold manifold = dispatcher.getManifoldByIndexInternal(i);

            if (manifold.getBody0() == colObj || manifold.getBody1() == colObj) {

                int numContacts = manifold.getNumContacts();
                for (int j = 0 ; j < numContacts ; j++) {

                    ManifoldPoint point = manifold.getContactPoint(j);

                    // Translate all contact points by dx
                    point.positionWorldOnB.add(dx);
                    point.positionWorldOnA.add(dx);

                }
            }
        }
    }
What am I missing here ? Is there some other internal data structure that would remember about the old positions ?

I'm aware I should probably use a linear velocity for all bodies involved and let the engine solve the displacement for me, but if I could avoid that, I would prefer doing it akin to the way presented above. One of the bodies is actually a Kinematic body (zero mass) that I don't want be subject to change in velocity from collisions from the other bodies, and the engine won't actually move a body even if specified a linear velocity unless that body has an actual mass.

Thank you for any tip,
Guillaume
Post Reply