General Bullet weirdness

cobolt_dink
Posts: 72
Joined: Fri Apr 04, 2008 6:07 pm

General Bullet weirdness

Post by cobolt_dink »

I have several stacks of rigid body objects, a world level made from btBvhTriangleMeshShape and a kinematic object bouncing around. When the kinematic object hits a rigid body it will destroy it and cause the rest of the stack to fall down. Sometimes it when it comes down the topmost block will only jump a bit, then other times the top block will bounce high enough to do a 180, and other times the whole stack will bounce high in the air. Also sometimes having a stack come down will cause a neighboring stack to fall over though it was never touched.

This one may be just how I've got my game loop but I run the game in window mode for debugging and if I drag the window around by the title bar all the rigid bodies shoot off into space.

Another weird thing (and this may be from me misusing the engine) is I have a field of kinematic objects sitting on a level and sometimes they will fly out into space (though very rare) and nothing has touched them. All I want is to have collision detection so having them as a kinematic object might be the wrong thing to do.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: General Bullet weirdness

Post by Erwin Coumans »

cobolt_dink wrote: This one may be just how I've got my game loop but I run the game in window mode for debugging and if I drag the window around by the title bar all the rigid bodies shoot off into space.
It sounds like you are using a variable timestep, which is not supported by Bullet.

Please call the dynamicsWorld->stepSimulation(deltaTime), and don't use zero as second argument. That guarantees a fixed internal timestep of 60 hertz.

Hope this helps,
Erwin
cobolt_dink
Posts: 72
Joined: Fri Apr 04, 2008 6:07 pm

Re: General Bullet weirdness

Post by cobolt_dink »

Yeah I had a variable timestep and made that change and it seems to be working better now.

Any idea on the others?
cobolt_dink
Posts: 72
Joined: Fri Apr 04, 2008 6:07 pm

Re: General Bullet weirdness

Post by cobolt_dink »

The jitter is also becoming a big problem. With my variable timestep the stacks will eventually fall over because of the jitter. Even if I go back to the 1/60 timestep there is a noticable movement when the physics start (they don't start right away). Is there any easy fix or do I have to start applying impulses to keep the blocks steady?
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: General Bullet weirdness

Post by Erwin Coumans »

Do the Bullet demos show the same jitter for you? There are many ways to introduce jitter (as with most physics engines) and ways to avoid it:
  • make sure to use small min/max world bounds for the broadphase, otherwise deactivation is ineffective.
  • allow sleeping/deactivation for stacks of objects.
  • use internal fixed timestep (you can still use a variable timestep, but don't use 0 as second argument to 'stepSimulation'. Bullet automatically interpolates
  • use normal gravity (0,-10,0)
  • avoid small objects (<0.2 units)
  • use objects sizes in meters, in range 0.4 to a few meters.
  • Avoid degenerate triangles
  • stick with the default collision margin
  • leave the default number of constraint solver iterations to 10
  • don't use zero friction, leave it default
  • don't use large restitution, keep it zero if possible
  • try using a larger inertia tensor to increase stability
There are many more reasons, these are just some general guidelines.

If this all doesn't help, I recommend trying out some other physics engines, like PhysX or ODE, and see if they suit you better. If so, please provide a reproduction case.
Hope this helps,
Erwin
cobolt_dink
Posts: 72
Joined: Fri Apr 04, 2008 6:07 pm

Re: General Bullet weirdness

Post by cobolt_dink »

Most of the init code I've taken from the tutorials. I did have resitution set at 0.8, friction at 0.2 and damping at 0 for both, I removed that and they seem to behave better. Though I do see a bit of 'shimmering', the block isn't moving but on a few of the blocks the edges shimmer back and forth. Also if I have stepSimulation(delta) it seems worse but if I use stepSimulation(delta, 0) its not to bad.

I was trying to put the stack to sleep when created by using ISLAND_SLEEPING, which does work fine. But when the bottom block is taken out I need to activate the other blocks. It works, unless the body is already active. If the body is active then it crashes at setActivation(). Any ideas for that? I do have the collision callback setup but I'm not trying to activate there. I set up a little message system that puts a message in a queue and outside the callback I go through the list and do actions. Maybe related to multiple of the same message getting posted if the callback is called multiple times for the same contact?

Physics aren't my bag so I'm sure I'm trying to do things I really shouldn't be and its causing me problems. As except for the little shimmer deal all the demos seem to work fine.