- Home /
Question by
cube_sniper24 · Aug 07, 2021 at 04:27 PM ·
procedural generationrocks
how to could I get the location and rotation of a random triangle in a mesh?
I used a tutorial to make a group of scripts for random land generation, and now I want to add objects onto the terrain, and I think that for rocks, if I get a triangle from the mesh, and instantiate a rock with the rotation and position of it, It will work. but I don't know how to get the position and rotation of any gives triangle on any mesh.
Comment
Answer by Llama_w_2Ls · Aug 07, 2021 at 04:48 PM
With mesh colliders, I believe a raycast returns a triangle index of the triangle it hit. You can get the triangle array from the mesh filter's mesh, and find the triangle that it hit. Then, use those as the indicies in the vertex array to find the vertices. Do some math, and you can get the pos/rot of that triangle.
Or use the normals. :)