Gravity doesn't work?

okoman
Posts: 3
Joined: Sat Nov 17, 2007 2:14 am

Gravity doesn't work?

Post by okoman »

Hi!
I'm trying to write a small physics simulation with Bullet. I think I did everything what's done in the BasicDemo, but unfortunately in my program gravity doesn't seem to work. :? I know it isn't a bug, it's a mistake in my code. But I do not really know where to start debugging. Collisions are okay and applied forces are working well, too. So it seems to be a specific problem concerning the gravity. I just set the force by executing

Code: Select all

mWorld->setGravity(btVector3(0,-9.81,0));
mWorld is a btDiscreteDynamicsWorld. Do I have to set up some more values? Probably for the bodies?
I hope you can help me solving that issue. :)
okoman
Posts: 3
Joined: Sat Nov 17, 2007 2:14 am

Re: Gravity doesn't work?

Post by okoman »

I figured out that the btRigidBody is neither a static nor a kinematic object and I think this is the problem. How can I fix it?
okoman
Posts: 3
Joined: Sat Nov 17, 2007 2:14 am

Re: Gravity doesn't work?

Post by okoman »

Okay. I forgot to set up the transform matrix. Sorry for spamming :wink:
hiker
Posts: 83
Joined: Tue Oct 24, 2006 11:52 pm
Location: Australia

Re: Gravity doesn't work?

Post by hiker »

Hi,
okoman wrote:I figured out that the btRigidBody is neither a static nor a kinematic object and I think this is the problem. How can I fix it?
I am not sure what you are trying to do, but static objects don't move at all, and kinematic objects are moved by your program (and not by bullet). If you want an object to be moved by gravity, it must be a dynamic rigid body (i.e. mass>0). So that should be correct.

The discrete dynamics world has a default gravity, and I set the gravity immediately after creating it. All rigid bodies added will get this gravity set (setGravity will apparently change the gravity of all dynamic bodies), so unless you explicitly set the gravity to 0 after adding a body to the dynamics world, everything should be fine.

Is it possible that a collision is happening, and that your object is actually resting? Try implementing the bullet debug drawer, and perhaps let the object start a bit higher, to see if it falling then (I had a problem once where a kart was stuck in the air, apparently because of some incorrect collision detection between a static triangle mesh and the kart. It was solved when I started using btBvhTriangleMeshShape with useQuantizedAabbCompression=true).

Hope that helps!
Joerg

EDIT: You were faster :) Well, I'll leave my comment here, might be useful for someone else.