I created a custom DetectFunctor which handles collisions between the built-in JigLibX types (boxes, etc) and my custom terrain (built from model vertex data). It works as expected with the exception of when an object is in constant contact with the terrain. In that situation, the object will seem to vibrate on the surface (in the y-axis).
I think my issue is with returning the penetration distance. Here is the code below that is in question:
public override void CollDetect(CollDetectInfo infoOrig, float collTolerance, CollisionFunctor collisionFunctor)
{
//SNIP!
Vector3 newPt = newPts[i], oldPt = oldPts[i];
float newDist;
Vector3 normal, collisionPosition;
bool immediateCheck = customTerrainPrim.RayIntersect(out newDist, out collisionPosition, out normal, oldPt, newPt);
if (immediateCheck)
{
if (newDist < collTolerance)
{
float oldDist = collisionPosition.Y + collTolerance;
The rest of the DetectFunctor is taken from the BoxHeightMap one (included in JibLibX). The RayIntersect method checks for a collision on a plane along the vector starting at oldPt and going to newPt. It returns true if there is a collision, and then the distance to the plane (from the starting point), the point of the collision, and the normal of the collided plane.
Initially, I tried setting the penetration to the distance between the end point of the ray and the collision point; however, that resulted in objects falling through the custom terrain. Setting the penetration to the height of the terrain at the collision keeps objects above it, but they vibrate.
Any ideas? Or maybe more information on what the penetration represents?
Thanks!





