• Advertisement
Sign in to follow this  

How to stiffly attach 2 objects together using btHingeConstraint in Bullet Physics

This topic is 1037 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys
 
I am building a car game with help of bullet physics and need help regarding a specific functionality.
I have attached a Canon to my car to shoot bullets. Actually my car body and the canon are two separate rigidbody objects attached using btHingeConstraint ( there is a reason why i have done that instead of using compoundshape). The canon is at right position and the shooting is also working perfectly. 
The problem happens when my car collides with a building. At this moment my canon dislodges from the car. Is there a way I can make canon stiffly bound tho the car using hingeconstarint only? I read bout CFM and ERP but they prove to be of no use. Here is a sample code -
                btVector3 cyl_coord = btVector3(0.5, 1, 1);
                btCollisionShape* suppShape = new btCylinderShapeZ(cyl_coord);
suppLocalTrans.setIdentity();
                suppLocalTrans.setOrigin(m_cameraPosition);
                m_canon = localCreateRigidBody(1,suppLocalTrans, suppShape); // Canon added to car
                
                btTransform localC, localD;
localC.setIdentity();
localD.setIdentity();
localC.getBasis().setEulerZYX(0, M_PI_2, 0);
localC.setOrigin(btVector3(0.0, 0.2, 1.05));
localD.getBasis().setEulerZYX(0, M_PI_2, 0);
                localD.setOrigin(btVector3(0.0, -1.5, -1.05));
m_liftHinge = new btHingeConstraint(*m_carChassis,*m_canon, localC, localD);// Creating the constraint
m_liftHinge->setLimit(0.0f, 0.0f);
                m_liftHinge->setParam( BT_CONSTRAINT_STOP_CFM, 0, -1);
m_dynamicsWorld->addConstraint(m_liftHinge, true);
 
Can any one help with this.

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement