compound shape help

Post Reply
codeman_nz
Posts: 4
Joined: Thu Aug 25, 2016 3:50 am

compound shape help

Post 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.
hyyou
Posts: 96
Joined: Wed Mar 16, 2016 10:11 am

Re: compound shape help

Post 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.
benelot
Posts: 350
Joined: Sat Jul 04, 2015 10:33 am
Location: Bern, Switzerland
Contact:

Re: compound shape help

Post by benelot »

hyou, what was colliding in your case? can the compound elements collide with each other?
hyyou
Posts: 96
Joined: Wed Mar 16, 2016 10:11 am

Re: compound shape help

Post 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.
benelot
Posts: 350
Joined: Sat Jul 04, 2015 10:33 am
Location: Bern, Switzerland
Contact:

Re: compound shape help

Post 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.
Post Reply