Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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) );



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

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:


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.

share|improve this answer
This is also done on the official 2D example:… which is labeled as "experiments" in the example browser. – Ciro Santilli 巴拿馬文件 六四事件 法轮功 May 3 at 6:43
"linear factor" stands for "linear damping factor" is that it Empty docs as usual :-s – Ciro Santilli 巴拿馬文件 六四事件 法轮功 May 3 at 6:53

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
Thank you! This is a great answer, since it also applies to the java port of JBullet as well (unlike the other answer). – joehot200 May 14 '15 at 10:41

Your Answer


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.