Locked axes are not completely locked

rpita
Posts: 4
Joined: Fri Mar 06, 2009 11:26 pm

Locked axes are not completely locked

Post by rpita »

Hi! :)

I am programming a breakout/arkanoid like game that uses bullet for collision detection and physics. To keep the balls in two dimensions I use the method described in the Wiki (Code Snippets). In short, I create a null body, attach the ball bodies and add a 6 DOF constraint for every ball. In that constraint I lock the third axis to keep the balls in one xy-plane.

This method works only when:
  • the local inertia of the balls is a zero vector
  • the restitution of the colliding bodies is set to something like 1
  • the friction of the colliding bodies ist set to 0
If this is not the case, sooner or later the balls wind out of the xy plane when colliding with another object with some strange movements . Is that a bug or a feature? :)



Another thing... I think sometimes it's difficult to integrate bullet into the game logic. For example when a ball collides with a brick, the brick have to disappear. I try to do this in the collision processed callback (BTW at the moment there is no extern declaration for gCollisionProcessedCallback in any of the header files). Of course, when I remove the brick body from the world at this point of the collision detection, it is removed before the physics algorithms have a chance to calculate the new velocity of the ball. Hence, the ball continue to move in the same direction as before. How is it possible to let the ball collide correctly with a brick and to remove the brick from the world?
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Locked axes are not completely locked

Post by Erwin Coumans »

The best way of locking the motion in 2D is using btRigidBody::setLinearFactor and btRigidBody::setAngularFactor.
  • btRigidBody::setLinearFactor takes a btVector3 as argument, where its x,y and z correspond to worldspace motion along those axis. Use a 1 to allow motion, and 0 to disallow motion along a certain axis.
  • The same for btRigidBody::setAngularFactor, where x,y and z corresponds to rotation along those axis.
For example, if you want to limit the motion of objects in the X-Z plane, and only rotation along the Y axis, use:

Code: Select all

body->setLinearFactor(btVector3(1,0,1));
body->setAngularFactor(btVector3(0,1,0));
This will be available in Bullet 2.75, and if you can't wait just download the latest SVN trunk version from the Bullet code repository at Google Code.
Hope this helps,
Erwin
rpita
Posts: 4
Joined: Fri Mar 06, 2009 11:26 pm

Re: Locked axes are not completely locked

Post by rpita »

Thank you very much, that sounds pretty convenient. :) I'm working with the trunk anyway. I'm not sure if I can test these new features more extensive before Thursday since our deadline is Wednesday and there is still plenty of work to do. :shock: