Sliding Boxes and Contact Caching

Please don't post Bullet support questions here, use the above forums instead.
noone688
Posts: 6
Joined: Fri Sep 10, 2010 2:13 pm

Sliding Boxes and Contact Caching

Post by noone688 »

Hi everyone!

I finally come to a point where I have to ask some of the experts here :D

Iam currently writing my own engine based on impulses. I use MPR for collision detection and get one collision point each physic update. Iam caching them in a similar way it is done in bullet: store all contacts as long as they don't become invalid. 'invalid' means that the penetration becomes negative (1) or the distance orthogonal to the contact normal exceeds a threshold (2). This all works well, iam able to stack many many objects without any jitter with a few iterations and 60fps. (So there seems to be at least no huge bug somewhere in the solver code).

The problem comes with sliding flat objects (here:boxes) : the boxes are in heavy jitter! this becomes really noticeable at even 60fps (I can post a video here if this helps). Of course this comes from dropping all the contact points because condition (2) is true. In the next frame only on collision point is detected which lets the box sink into the ground.. and so on... I can get rid of the problem by setting the threshold of (2) to very heigh values but that also gives strange results for stacked objects - contacts are hard to destroy and friction doesn't look right. - Iam pretty sure that it is possible to slide boxes at 60fps without the noteable jitter- something is going wrong.

Any thoughts on this? How do you store your contacts?
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Sliding Boxes and Contact Caching

Post by Erwin Coumans »

1) You can gather multiple points by perturbing the object around the separating vector.

2) Don't throw away contacts immediately when the distance is above 0 (separation) but use a positive threshold value. Make sure that your constraint solver can deal with positive contacts (like Bullet's solver) and it will improve stability.

3) Some games using Bullet used another trick: only dropping one contact per simulation frame.

Both (1) and (2) have been implemented in Bullet.
You can enable (1) using

Code: Select all

collisionConfiguration->setConvexConvexMultipointIterations(...)
See Bullet/Demos/InternalEdgeDemo and Bullet/Demos/CollisionDemo/CollisionDemo.cpp for details.
(2) can be controlled using

Code: Select all

object->setContactProcessingThreshold(0.03);
You can also check out my GDC 2010 slides on contact generation.

Thanks,
Erwin
noone688
Posts: 6
Joined: Fri Sep 10, 2010 2:13 pm

Re: Sliding Boxes and Contact Caching

Post by noone688 »

Thank you Erwin for the detailed and quick reply. Sadly I already read through the forums and tried all the suggestions you summuarized here:

(1) I want to get it stable as possible without that "trick" first.
(2) Already included.
(3) Already tried that, I gave each contact a "livetime" and only removed the oldest. Sadly it helped not that much.

I think something else is really going wrong with the contacts (or maybe the timestepping). I only need the confirmation that the jitter I observe is not normal at 60fps. Here is a video: (youtube) http://www.youtube.com/watch?v=IIWHILaCkLc

Thanks
Dirk Gregorius
Posts: 861
Joined: Sun Jul 03, 2005 4:06 pm
Location: Kirkland, WA

Re: Sliding Boxes and Contact Caching

Post by Dirk Gregorius »

You can always compare your demos to Bullet, but note that Bullet uses a special box-box collider which finds all contact points per frame. In my test framwork I can compare all engines (Bullet, Havok, PhysX) and I have a switch to make all boxes convex hulls which forces them through the general convex collider. I suggest to re-run some of the bullet demos yourself and compare. I also notice some drop in quality with incremental manifolds.

HTH,
-Dirk
noone688
Posts: 6
Joined: Fri Sep 10, 2010 2:13 pm

Re: Sliding Boxes and Contact Caching

Post by noone688 »

:oops: I accidentally called "IntegrateForces" twice. Which gave me some extra velocity within the timestepping. It's still a bit jittery but thats the expected jitter using incremental manifolds.

Nervertheless thank you very much for your knowledge. Awesome forum support.