How do i identify the triangle i collide with in my mesh collider?
Depending on if you use a convex meshcollider or not, the collider mesh doesn’t need to be the same as your actual visual mesh. If it is the same (so you don’t have Convex ticked) You still need to raycast it manually since a collision can have multiple hit points and they don’t provide this information for each point.
You just have to use Collider.Raycast, which only can hit this collider, and cast a ray along the inverse collision normal towards the collision point. The resulting RaycastHit has a triangleIndex which tells you in which triangle the point is.
edit Something like that:
// C#
void OnCollisionEnter(Collision col)
{
// We just take the first collision point and ignore others
ContactPoint P = col.contacts[0];
RaycastHit hit;
Ray ray = new Ray(P.point + P.normal * 0.05f, -P.normal);
if (P.otherCollider.RayCast(ray, out hit, 0.1f))
{
int triangle = hit.triangleIndex;
// do something...
}
else
Debug.LogError("Have a collision but can't raycast the point");
}