Since no one directly answered his question, I guess I will.
function getGroundPlane(%offset)
{
%ray = containerRayCast(vectorAdd("0 0 1", %offset), vectorAdd("0 0 -1"), $TypeMasks::TerrainObjectType);
%obj = getWord(%ray, 0);
if(isObject(%obj))
return %obj;
error("No ground plane found! Using box search.");
%box = initContainerBoxSearch(vectorAdd("0 0 0", %offset), "0 0 1", $TypeMasks::TerrainObjectType);
%obj = containerSearchNext();
if(isObject(%obj))
return %obj;
error("No ground plane found! I don't know why. You forgeted something up I guess.");
return 0;
}
I added a box search backup because in my experience direct raycasts can be fussy, but are preferred to box searches. You could cut out the top half if you wanted.