Hi
I’ve been trying to make Physics.Boxcast work and spent a few hours fiddling with it without much success, until I discovered that it apparently ignores mesh colliders. I’ve tried replacing my mesh with a box collider and then everything starts working like a charm; but I really need my collider to have the same shape as my mesh, so a box collider will just not work.
Does anyone know if this is a known issue? May I be doing something wrong?
My code does the following: It gets two items, a terrain like(but not a unity terrain) mesh (target) and a cube clipping with that mesh in y axis (origin). Then it trows a boxcast in the containing box of the cube to detect the lowest point of the mesh, still in the cube’s bouding area; I’m getting the lowest point of the mesh located below the cube.
public static float LocateLowestCollidingSection(GameObject origin, GameObject target){
Mesh originMesh = origin.GetComponent<MeshFilter>().mesh;
RaycastHit hit;
float searchMargin = 50f;
if (Physics.BoxCast (new Vector3 (origin.transform.position.x, origin.transform.position.y - searchMargin, //- originMesh.bounds.extents.y/2f,
origin.transform.position.z),
new Vector3 (originMesh.bounds.extents.x, 0.1f, originMesh.bounds.extents.z),
Vector3.up, out hit, Quaternion.identity, searchMargin + originMesh.bounds.extents.y, ~target.layer)){
return hit.point.y;
} else {
Debug.LogError ("And thus, only ethernal void remains below the target.");
return Mathf.Infinity;
}
}