Sign in to follow this  
shashwatsher

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this