[Solved] Sphere bounce problems on triangle mesh
Posted: Thu Jun 12, 2014 11:39 pm
I just wanted to share my experience investigating problems I encountered with a sphere bouncing/colliding with triangle mesh geometry, for posterity.
The first problem I was having was that a sphere bouncing on flat ground would come to rest much sooner than expected. I tracked this down to this line of code:
I'm not really sure what this code's purpose is, but it was basically reducing the restitution of the bouncing sphere. Commenting it out fixed the bouncing, however now the sphere would occasionally pop up off of the flat triangle mesh if the sphere was rolling along the mesh. I tracked this down to a problem with the contact point. You would expect the contact point between a sphere and flat ground to be directly below the center of the sphere, but sometimes it was being offset. I tracked this down to the code in:
I added the following code which fixed my problem:
The first problem I was having was that a sphere bouncing on flat ground would come to rest much sooner than expected. I tracked this down to this line of code:
Code: Select all
btSequentialImpulseConstraintSolver::setupContactConstraint( ... )
...
velocityError -= penetration / infoGlobal.m_timeStep;Code: Select all
SphereTriangleDetector::collide( ... )
...
if (isInsideContactPlane) {
if (facecontains(sphereCenter,vertices,normal)) {
...
} else {
// !!! The code here sets the contact point to a point on one of the edges of the triangle rather a point that is towards the sphere's centerCode: Select all
// if the triangle is part of a triangle mesh and is perfectly flat on the ground,
// then we want the contact point to be perfectly below the ball, not off to the side a bit (which causes
// the ball to skip up off the ground)
if ( hasContact ) {
contactPoint = sphereCenter - normal*distanceFromPlane;
}