Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I want to create an object than only moves along the the X and Z axes, while keeping the Y-axis disabled (it's like movement in 2D, and the object wont fall down).

I'm currently using a 6 dof constraint to restrict movement in the Y-axis, but it's not working:

btRigidBody* zeroBody = new btRigidBody(0, NULL, NULL); // Create the body that we attach things to
btRigidBody* robot = mCarChassis->getBulletRigidBody();

btGeneric6DofConstraint* constrict = new btGeneric6DofConstraint(*robot, *zeroBody, btTransform::getIdentity(), btTransform::getIdentity(), false);

constrict->setLinearLowerLimit( btVector3( 1, 1, 1));
constrict->setLinearUpperLimit( btVector3(-1, 1,-1));

constrict->setAngularLowerLimit( btVector3( 1,  1,  1) );
constrict->setAngularUpperLimit( btVector3(-1, -1, -1) );

mBulletWorld->getBulletDynamicsWorld()->addConstraint(constrict);

Thanks!

share|improve this question
    
Maybe this will help: bulletphysics.org/Bullet/phpBB3/…, perhaps also set the Lower/Upper limits for the Y-axis to 0, instead of 1. –  Daniel Jan 12 '12 at 23:20

2 Answers 2

The preferred way to achieve this in Bullet is to set the linear factor and possibly the angular factor for the body in question. This method is presented as a Code Snippet at the Bullet Wiki page.

In order to allow movement along only the Y-axis, you would use something like this:

body->setLinearFactor(btVector3(0,1,0));

If you additionally wish to disable rotation around any particular axis, you use the same procedure, but using the setAngularFactor function instead.

In this simple example video I have used the following two calls in order to disable movement along the Y-axis and to allow rotation around only the Y-axis. This effectively forces the body to remain in the XZ-plane in which it was initially created.

body->setLinearFactor(btVector3(1,0,1));
body->setAngularFactor(btVector3(0,1,0));
share|improve this answer

One way to do this is to create a physics tick callback. This will be called every time bullet ticks internally. In this call back you can set the Y velocity to 0, effectively disabling Y movement. It would look something like this:

void myTickCallback(const btDynamicsWorld *world, btScalar timeStep) {
    //robotBody is the btRigidBody you want to constrain the movement of
    btVector3 velocity = robotBody->getLinearVelocity();
    robotBody->setLinearVelocity(velocity.x, 0, velocity.z);
} 

You can read more about simulation tick callbacks here.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.