Comments and answers for "Detect vertex hit and its neighbors by RaycastHit??"
http://answers.unity.com/questions/182212/detect-vertex-hit-and-its-neighbors-by-raycasthit.html
The latest comments and answers for the question "Detect vertex hit and its neighbors by RaycastHit??"Comment by ina on ina's answer
http://answers.unity.com/comments/894691/view.html
did you add meshcolliders to your procedural mesh? - what do you mean you can't get a hit?Fri, 06 Feb 2015 01:16:39 GMTinaAnswer by Bunny83
http://answers.unity.com/answers/355955/view.html
Loius is almost right. It's the triangle index. By multiplying it by 3 you get the index of the first **vertex index**. It should be like this:
// Should work in C# and UnityScript
// ...
var MC = hit.collider as MeshCollider;
if (MC != null)
{
var mesh = MC.sharedMesh;
var index = hit.triangleIndex * 3;
var hit1 = mesh.vertices[mesh.triangles[index ]];
var hit2 = mesh.vertices[mesh.triangles[index + 1]];
var hit3 = mesh.vertices[mesh.triangles[index + 2]];
}
Those are the 3 vertices that surround the hit point.
Keep in mind that hit.triangleIndex **only** works with a MeshCollider. No other collider will give you that information since they are pure mathematical colliders which are not based on triangles.Wed, 28 Nov 2012 23:22:32 GMTBunny83Comment by Loius on Loius's answer
http://answers.unity.com/comments/355927/view.html
That would be an index into the mesh.vertices array:
hit1 = mesh.vertices[triangleIndex*3];
hit2 = mesh.vertices[triangleIndex*3+1];
hit3 = mesh.vertices[triangleIndex*3+2];Wed, 28 Nov 2012 22:15:38 GMTLoiusAnswer by MrVerdoux
http://answers.unity.com/answers/355773/view.html
RaycastHit has a property called triangleIndex that tells you what the index of the triangle that was hit. I can't be much more concrete about this since I still couldn't even "hit" my procedural mesh, but that's other story. When I have some success, if you are still doubting about this I will try to be more helpful.Wed, 28 Nov 2012 21:30:52 GMTMrVerdoux