need Help with resolving of collisions

th-busch
Posts: 2
Joined: Tue Dec 11, 2007 8:16 am

need Help with resolving of collisions

Post by th-busch »

Hello, my name is thomas,
at first i like to thank you for making this wonderful lib and releasing it to the public.
i'm trying to use bullet for collision detection in my current project, but i'm having some problems with resolving the collisions right.

in my project, you control a character though a 3d world using the keyboard, so the characters (a btCylinderShape right now) position gets updated every frame and then collision detection is performed.

this is how i try to resolve the collisions now (i've taken that from the collisionInterfaceDemo):

Code: Select all

	
		mCollisionWorld->performDiscreteCollisionDetection();
		int numManifolds = mCollisionWorld->getDispatcher()->getNumManifolds();
		for (int i=0;i<numManifolds;i++)
		{
			btPersistentManifold* contactManifold = mCollisionWorld->getDispatcher()->getManifoldByIndexInternal(i);
			btCollisionObject* obA = static_cast<btCollisionObject*>(contactManifold->getBody0());
			btCollisionObject* obB = static_cast<btCollisionObject*>(contactManifold->getBody1());
			contactManifold->refreshContactPoints(obA->getWorldTransform(),obB->getWorldTransform());

			int numContacts = contactManifold->getNumContacts();
			for (int j=0;j<numContacts;j++)
			{
				btManifoldPoint& pt = contactManifold->getContactPoint(j);
				btVector3 translate = pt.m_normalWorldOnB * (-pt.getDistance());
//apply translate Vector to ObjectA
}
}
the problem is that ObjectA is translated to far away from ObjectB (it's not stuck on it's surface), so when i have muliple reoccurring collisions (when, for example the caracter runs in front of a wall), objectA is jittering in front of objectB and sometimes it even slips though after a while.

so my question is, is there anything wrong with the above code? or is it bettewr to use the dynamics part of bullet for that? i'm a totally newb on both, 3d and physics.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: need Help with resolving of collisions

Post by Erwin Coumans »

A character control will be added 'really soon now' (TM) ;-)

Make sure you only push the character out of penetration when the contact point distance is smaller then zero. Also, note that using all contact points to recover from penetration is too much. You can use relaxation to relieve this problem: push the character out less then the full distance (use a bias variable, and set it to say 0.1), and then iterate a few times over all contact manifolds.

Even better is to use the velocity to predict the collision, using CCD query. The character control demo will show how to do this.

Hope this helps,
Erwin
th-busch
Posts: 2
Joined: Tue Dec 11, 2007 8:16 am

Re: need Help with resolving of collisions

Post by th-busch »

thank you for your reply,
i have added the bias variable and did 5 iterations instead of one, also i added a check for the distance if it is smaller than zero. now there is much less jittering than before but it's still there. i think i have to clean up my character controlling code and then maybe use CCD query to handle the collisions (i only have to find out how :lol: ).

anyways, thanks for helping me
thomas