Page 1 of 1

compound shape help

Posted: Thu Aug 25, 2016 3:55 am
by codeman_nz
Hi everyone,

I'm trying to create a compound shape with two boxes which will be used as the players rigid body so it will move around. But when I create it the shape moves by itself. Here is the code:

Code: Select all

btBoxShape *legsBoxShape = new btBoxShape(btVector3(0.1, 0.2, 0.05));
compoundShape->addChildShape(btTransform(btQuaternion(0, 0, 0, 1), btVector3(0, 0.2, 0)), legsBoxShape);

btBoxShape *bodyBoxShape = new btBoxShape(btVector3(0.4, 0.2, 0.4));
compoundShape->addChildShape(btTransform(btQuaternion(0, 0, 0, 1), btVector3(0, 0.6, 0)), bodyBoxShape);

btDefaultMotionState* compoundBoxMotionState = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(2, 0.4, 0)));

btScalar compoundMass = 1;
btVector3 compoundFallInertia(0, 0, 0);
compoundShape->calculateLocalInertia(compoundMass, compoundFallInertia);

btRigidBody::btRigidBodyConstructionInfo compoundRigidBodyCI(compoundMass, compoundBoxMotionState, compoundShape, compoundFallInertia);
btRigidBody* compoundRigidBody = new btRigidBody(compoundRigidBodyCI);
dynamicsWorld->addRigidBody(compoundRigidBody);
I'm new to using bullet so I'm probably doing this wrong. Any help is appreciated.

Re: compound shape help

Posted: Fri Aug 26, 2016 5:07 am
by hyyou
I had this problem once. It was exactly about compound-shape & move-by-itself.
To debug, make sure you have only 1 body (the compound) in the world & no gravity.
Let's see if it still dare to move by itself.
In my case, the velocity came from an invisible collision response, and it was bug in my part.

Re: compound shape help

Posted: Fri Aug 26, 2016 6:51 pm
by benelot
hyou, what was colliding in your case? can the compound elements collide with each other?

Re: compound shape help

Posted: Tue Aug 30, 2016 2:40 pm
by hyyou
benelot, for me it is Rigid (simple shape) vs Compound.

I tried to do a merge C1+C2->B, but I forget to disable C1 & C2.

Re: compound shape help

Posted: Wed Aug 31, 2016 8:00 am
by benelot
hyyou, that is what I thought. Also I think that this is the issue with OPs problem. I had cases with constraint setups that moved by themselves because they were constantly colliding.