[Solved] Sphere bounce problems on triangle mesh

Post Reply
cj3j
Posts: 8
Joined: Wed Nov 20, 2013 6:40 am

[Solved] Sphere bounce problems on triangle mesh

Post by cj3j »

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:

Code: Select all

btSequentialImpulseConstraintSolver::setupContactConstraint( ... )
...
velocityError -= penetration / infoGlobal.m_timeStep;
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:

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 center
I added the following code which fixed my problem:

Code: 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;
}
Post Reply