0
\$\begingroup\$

I'm trying to create procedurally generated tiles and I've reached a point where I need to figure out the boundaries of the mesh or the outer vertices of the mesh.

enter image description here

    RaycastHit hit;
    if (Physics.Raycast(bound[ i ].v2, Vector3.forward, out hit)) {
    if (hit.distance > 2) {

I've tried raycasting all the vertices, but still can't get the vertices of the edge. The mesh does have a collider. any help on how i would go about this is appreciated, Thanks.

\$\endgroup\$
1
\$\begingroup\$

Have you seen this post about getting the outer/edge vertices from a Mesh? http://answers.unity3d.com/questions/1019436/get-outeredge-vertices-c.html

\$\endgroup\$
2
  • \$\begingroup\$ Link-only answers are generally discouraged. Adding a basic summary of the key points recommended at the link would make this answer both clearer and more future-proof in case of link rot. ;) \$\endgroup\$
    – DMGregory
    Jul 27 '16 at 22:01
  • \$\begingroup\$ i did check that out, but it didn't work \$\endgroup\$ Jul 28 '16 at 4:44
0
\$\begingroup\$

If your mesh will always be a rectangle you could use the MeshCollider, or more specifically MeshCollider.bounds.extents but that will only return 1/2 the width, length and height, not the vertices.

Depending on what you need to accomplish or the environment you are creating, this may work. If not, let us know what you plan on doing with the data after you get it and that may help clear things up.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.