GameObject TempGameObj = new GameObject ();
TempGameObj.transform.position = TempGameObj.transform.localPosition = Vector3.zero;
MeshCollider PixelCollider = TempGameObj.AddComponent<MeshCollider> ();
PixelCollider.enabled = true;
Vector3[] TrianglePoints = new Vector3[3] {
new Vector3 (0.4999, 0, 0.9999),
new Vector3 (0.0001, 0, 0.9999),
new Vector3 (0.0001, 0, 0.5001)
};
int[] TriangleTriangles = new int[3] {
0, 1, 2
};
Mesh TriangleMesh = new Mesh ();
TriangleMesh.vertices = TrianglePoints;
TriangleMesh.uv = new Vector2[3] {
new Vector2 (0.4999, 0.9999),
new Vector2 (0.0001, 0.9999),
new Vector2 (0.0001, 0.5001)
};
TriangleMesh.triangles = TriangleTriangles;
TriangleMesh.Optimize ();
PixelCollider.sharedMesh = TriangleMesh;
PixelCollider.cookingOptions = MeshColliderCookingOptions.EnableMeshCleaning;
// yield return new WaitForFixedUpdate (); // This slows it down, but did not fix it.
// Physics.SyncTransforms (); // This also slows it down and did not fix it.
Ray UV_Pointer = new Ray ( new Vector3 ( 0.001026562, 4.0f, 0.5028797 ), Vector3.down );
if ( PixelCollider.Raycast ( UV_Pointer, out BarycentricGenerator, 5.0f ) == false )
{
// Debug.Log ( "ERROR! Raycast failed!\n" );
}
It always fails on this, but it succeeds dozes of times all over 4 other triangles. All of the triangles are flat, at height 0.
Sometimes it succeeds in other points within the triangle, other times it continuously fails.
I set all of the points in Blender and they line up, so it SHOULD intersect. I did the intersection through Plane.Raycast and that seemed to work.
So my questions are:
Does anyone have any idea why it is failing?
Is this an engine glitch?