Hi,
I have implemented collision on wall segments (single .dae model) in a game using
bullet physics. Now I want the wall to have a door, and to open and let the player through,
so basically create a hole in the shape. There is a wall model with a door that is animated already.
What would be best practice here?
- Remove the RigidBody from the collisionWorld and add a new one when door opens/closes
- track it outside the world by reference and somehow manipulate the sub shape (I'm assuming this will need a CompoundShape)
Is there some other approach that is better?
Best regards
Andreas
Hobby programmer
Changing the shape of a rigid body (opening a door in wall)
-
- Posts: 3
- Joined: Fri Aug 03, 2012 2:18 pm
-
- Posts: 6
- Joined: Tue Aug 07, 2012 3:27 am
Re: Changing the shape of a rigid body (opening a door in wa
Hello, I'm new to bullet but I did something similar in the game I'm working on so maybe I can help. (I have a door that the player can push to open/close.)
You can use a "spDoorHinge" constraint from the bullet Constraints Demo. I have the wall with the hole for the door and the door is just a btRigidbody in the shape of a door with a btHingeConstraint applied to it.
So my code to create/add the door to the dynamicsworld is something like this:
Hope this helps. This is my first post here so hopefully this comes out ok. I tried adding some comments just now hopefully they aren't too confusing...lol
Check the Constraint Demo for the btHingeConstraint.
You can use a "spDoorHinge" constraint from the bullet Constraints Demo. I have the wall with the hole for the door and the door is just a btRigidbody in the shape of a door with a btHingeConstraint applied to it.
So my code to create/add the door to the dynamicsworld is something like this:
Code: Select all
//door
btCollisionShape* pDoorShape = new btBoxShape(btVector3(5.0f, 5.9f, 0.5f)); //the door shape
trans.setIdentity();
trans.setOrigin(btVector3(105.0f, 2.0f, 29.5f)); //position of the door
motionState = new btDefaultMotionState(trans);
pDoorBody = new btRigidBody(btScalar(1.0), motionState, pDoorShape, btVector3(1,1,1)); //mass=1.0
const btVector3 btPivotA(4.8f , 0.0f, 0.0f ); // position of the door pivot
btVector3 btAxisA( 0.0f, 1.0f, 0.0f ); // pivot pointing up Y-axis (rotate on Y axis)
btHingeConstraint* spDoorHinge;
spDoorHinge = new btHingeConstraint( *pDoorBody, btPivotA, btAxisA );//add HingeConstraint to the door
spDoorHinge->setLimit( -PI * 0.5f, PI * 0.5f ); //set door movement limit from -90° to+90° (PI=3.1415)
dynamicsWorld->addConstraint(spDoorHinge); //add door hinge constraints to the world
dynamicsWorld->addRigidBody(pDoorBody); //add door to the world
//If you want to dampen the movement of the door you can do
pDoorBody->setDamping(1.4f,0.0); // modify the first argument to increase damping strength.
pDoorBody->applyDamping(1.4);
Check the Constraint Demo for the btHingeConstraint.
Last edited by Shogo on Fri Aug 17, 2012 1:13 pm, edited 1 time in total.
-
- Posts: 22
- Joined: Sat Nov 26, 2011 5:41 pm
Re: Changing the shape of a rigid body (opening a door in wa
Usually it is better to remove the body and insert a new, modified body. There are some issues/bugs with trying to change the shape of existing objects in some situations.. you'll think it works and then it'll bug out somewhere else..andreas wrote:Hi,
What would be best practice here?
- Remove the RigidBody from the collisionWorld and add a new one when door opens/closes
- track it outside the world by reference and somehow manipulate the sub shape (I'm assuming this will need a CompoundShape)
Is there some other approach that is better?

Or use a real simulated physical door like the other poster suggested.
-
- Posts: 6
- Joined: Wed Feb 20, 2013 6:14 am
Re: Changing the shape of a rigid body (opening a door in wa
how to converts an axis vector, or direction vector, from the world coordinate system to a body's local coordinate system ?