For some reason my Physics.Raycast isn’t hitting anything:
Vector3 endPoint = Vector3.zero;
for (int e = 0; e < mesh.vertices.Length; e++)
{
Vector3 StartPoint = mesh.normals[e] * (Radius + MaxHeight + 10.0f);
RaycastHit hit;
if (Physics.Raycast(endPoint, StartPoint, out hit))
{
Debug.DrawLine(StartPoint, hit.point, Color.yellow);
Debug.DrawLine(hit.point, endPoint, Color.red);
colors[e] = new Color(0.5f, 0.5f, 0.5f, 1.0f);
}
else
{
Debug.DrawLine(StartPoint, endPoint, Color.green, 5f);
}
}
I have tried with both a MeshCollider and a spherecollider and none of the rays turn either yellow or red, they remain green. Am I using it wrong?
EDIT: It seems that it doesn’t hit because there isn’t any collider, even though I have a meshcollider attached to it.
I update my meshcollider like so:
mesh.Clear();
mesh.vertices = vert;
mesh.normals = norm;
mesh.triangles = tri;
mesh.uv = uv;
mesh.RecalculateBounds();
mesh.RecalculateNormals();
mc0.sharedMesh = null; // nullify the previous sharedMesh
mc0.sharedMesh = mesh;
mc0.enabled = false;
mc0.enabled = true;