public static bool CCDSphereCast(Ray ray, float radius, ConvexShape target, ref RigidTransform shapeTransform, float maximumLength,
out RayHit hit)
{
int iterations = 0;
while (true)
{
if (GJKToolbox.SphereCast(ray, radius, target, ref shapeTransform, maximumLength, out hit) &&
hit.T > 0)
{
//The ray cast isn't embedded in the shape, and it's less than maximum length away!
return true;
}
if (hit.T > maximumLength || hit.T < 0)
return false; //Failure showed it was too far, or behind.
radius *= MotionSettings.CoreShapeScaling;
iterations++;
if (iterations > 3) //Limit could be configurable.
{
//It's iterated too much, let's just do a last ditch attempt using a raycast and hope that can help.
return GJKToolbox.RayCast(ray, target, ref shapeTransform, maximumLength, out hit) && hit.T > 0;
}
}
}
}