I make an adventure game like tomb raider with bullet and Ogre 3d. And I have a problem to displace crates or boxes.
I use a btGeneric6DofConstraint in order to push/pull some crates with my character. It works, the crate move with my hero.
But i want also that when my hero turn around himself in 360°, I want that my crate around my hero but i don't know how to do that. When I turn, the crate doesn't move.
here my code:
Code: Select all
btVector3 localpivot = pDeplacable->mRigidBody->getWorldTransform().inverse()*mPJ->mCharacter->getGhostObject()->getWorldTransform().getOrigin();
btQuaternion btQuat = mPJ->mCharacter->getGhostObject()->getWorldTransform().getRotation();
btTransform btT(btQuat, localpivot);
dof6 = new btGeneric6DofConstraint(*pDeplacable->mRigidBody, btT, true);
dof6->setAngularLowerLimit(btVector3(0, 0, 0));
dof6->setAngularUpperLimit(btVector3(0, 0, 0));
mPJ->mWorld->getBulletDynamicsWorld()->addConstraint(dof6,true);
float cfm = 0.5f;
dof6->setParam(BT_CONSTRAINT_STOP_CFM, cfm, 0);
dof6->setParam(BT_CONSTRAINT_STOP_CFM, cfm, 1);
dof6->setParam(BT_CONSTRAINT_STOP_CFM, cfm, 2);
dof6->setParam(BT_CONSTRAINT_STOP_CFM, cfm, 3);
dof6->setParam(BT_CONSTRAINT_STOP_CFM, cfm, 4);
dof6->setParam(BT_CONSTRAINT_STOP_CFM, cfm, 5);
float erp = 0.5f;
dof6->setParam(BT_CONSTRAINT_STOP_ERP, erp, 0);
dof6->setParam(BT_CONSTRAINT_STOP_ERP, erp, 1);
dof6->setParam(BT_CONSTRAINT_STOP_ERP, erp, 2);
dof6->setParam(BT_CONSTRAINT_STOP_ERP, erp, 3);
dof6->setParam(BT_CONSTRAINT_STOP_ERP, erp, 4);
dof6->setParam(BT_CONSTRAINT_STOP_ERP, erp, 5);
Code: Select all
if (dof6 != NULL && mPJ->interaction == 2){
btVector3 dir = btVector3(myHero->mNode->getOrientation().zAxis().x, myHero->mNode->getOrientation().zAxis().y, myHero>mNode->getOrientation().zAxis().z);
//dir.normalize();
btVector3 newPivot =myHero->mCharacter->getGhostObject()->getWorldTransform().getOrigin()*dir;
dof6->getFrameOffsetA().setOrigin(newPivot);
}