Hello everybody.
I'm planning on making a two dimensional game and want to use realistic physics.
Bullet seems like a very good physics engine, is there any way to implement in 2D?
thanks
Bullet in 2D?
- Erwin Coumans
- Site Admin
- Posts: 4221
- Joined: Sun Jun 26, 2005 6:43 pm
- Location: California, USA
- Contact:
Re: Bullet in 2D?
You could add a 'planar' constraint that keeps the rigid bodies in a 2D plane. This can be done using the btGeneric6DofConstraint with the correct settings (a sample showing how to do this would be useful indeed).Jesse_yay wrote:Hello everybody.
I'm planning on making a two dimensional game and want to use realistic physics.
Bullet seems like a very good physics engine, is there any way to implement in 2D?
thanks
Alternative, you could check out a very similar physics engine called Box2D. Most of the ideas and algorithms are the same, but then all in 2D.
Hope this helps,
Erwin
Re: Bullet in 2D?
I just did this the other day. I was hoping someone here might be able to comment on the validity of what I've done. I created a body with no shape or mass, and just left it. Then create another body [the one I actually wish to attach to the plane z=0] and attach it to the first one with a generic6dof:
is in my main physics class. Then when I create the actual ship bodies, I do thus:
Does that look right, to the more experienced bullet coders here?
Thank-you very much,
Gary (-;
Code: Select all
btCollisionShape *mZeroFloorShape;
btRigidBody *mZeroFloorBody;
mZeroFloorShape = NULL;
mZeroFloorBody = new btRigidBody(0,NULL,mZeroFloorShape); // z=0 body
mWorld->addRigidBody(mZeroFloorBody);
Code: Select all
btRigidBody *mShipBody;
/* Do all the ship-body-creation-stuff */
btGeneric6DofConstraint *mShiptoworld;
btTransform identity = btTransform::getIdentity();
mShiptoworld = new btGeneric6DofConstraint(*mShipBody, *mTWPhysics->getZeroPlane(),
identity, identity, false);
mShiptoworld->setLimit(0,1,0); // Disable X axis limits
mShiptoworld->setLimit(1,1,0); // Disable Y axis limits
mShiptoworld->setLimit(2,0,0); // Set the Z axis to always be equal to zero
mShiptoworld->setLimit(3,1,0); // Uncap the rotational axes
mShiptoworld->setLimit(4,1,0); // Uncap the rotational axes
mShiptoworld->setLimit(5,1,0); // Uncap the rotational axes
mTWPhysics->addConstraintToWorld(mShiptoworld);// small wrapper
Thank-you very much,
Gary (-;
Re: Bullet in 2D?
do this work for you ?
btw, when i searched this forum to find this topic using "bullet in 2d" as search phrase it failed saying that words are too common or too short, hopefully this can be improved
btw, when i searched this forum to find this topic using "bullet in 2d" as search phrase it failed saying that words are too common or too short, hopefully this can be improved
Re: Bullet in 2D?
Well, it certainly *seems* to be working...
Gary (-;
Gary (-;