Untitled

 avatar
unknown
csharp
8 months ago
1.2 kB
17
Indexable
    public void MoveHands(MeshFilter filter)
    {
        Mesh mesh = filter.mesh;
        List<Vector3> vertices = mesh.vertices.ToListPooled();
        Vector3[] normals = mesh.normals;
        Vector3 BestVert = Vector3.zero;



        foreach (Transform finger in Fingers)
        {
            foreach (Vector3 vertex in vertices)
            {
                if (BestVert == Vector3.zero || Vector3.Distance(finger.position, vertex) < Vector3.Distance(finger.position, BestVert))
                {
                   
                    BestVert = vertex;
                }
            }

            //convert the vertex from local space on the mesh, to world space
            Vector3 VertWorldPos = filter.transform.TransformPoint(BestVert);

            //this is in the right spot every time
            TestCube.position = VertWorldPos;

            //convert the vertex to the objects local space and set it's transform
            finger.position = finger.InverseTransformPoint(VertWorldPos);


            //irrelavant to the current issue
            finger.rotation = Quaternion.Euler(normals[vertices.IndexOf(BestVert)]);
        }
    }
Editor is loading...
Leave a Comment