- Home /
Mesh polygon of a hit surface on a gameobject
Are there methods in Unity that make getting the polygon/face on a "hit surface" on an arbitrary gameobject easy?
Answer by kolban · Apr 27, 2012 at 10:11 PM
In Unity, all objects are made up of meshes and meshes are made up of triangles. So when you ask about getting the polygon/face of the hit surface, I think what you are asking for is the identity of the triangle that was collided. When a collision occurs, we are given information about the collision including the point in world space where the collision happened. Our goal then would be to map that 3D point to the triangle of a mesh. It seems that if we cast a ray "close" to that point and "through" that point, we will generate a RaycastHit object. See:
http://unity3d.com/support/documentation/ScriptReference/RaycastHit-triangleIndex.html
This object has a property called "triangleIndex" which is an index into the array of triangles that compose the mesh that was struck by the ray ... and hence the triangle which was struck.
Hmm what I mean are all the triangles that are parallel to each other on the same plane... for example, if you hit a side of a cube, I would like to retrieve both triangles there.
@ina ,
Hi again. This would help me a lot in my project so I'm asking this. Did you find a way to access the surface of a gameobject which has been hit by a Raycast.
Thanks, Pranav Gadamsetty