Question by
umurcg · Sep 12, 2016 at 04:14 PM ·
verticesblendshapes
Does changin blend shape keys change location of vertices?
Hello, I have an object that I implement blend shape key. In game this key changes and it modifies mesh. My question is; does vertices change its location while key is changing. Because I am trying to force another object to follow one of the vertex of this mesh while key is changing. But it doesn't work. And according to my output vertex position doesn't change while key is changin.
Here is the code:
using UnityEngine;
using System.Collections;
public class VertexFollower : MonoBehaviour {
int nearestVertex;
// Use this for initialization
void Start(){
}
void Awake () {
nearestVertex= findNearestVertex ();
}
// Update is called once per frame
void Update () {
Mesh parentMesh=this.GetComponentInParent<MeshFilter> ().mesh;
print (nearestVertex);
print (parentMesh.vertices [nearestVertex]);
transform.position = parentMesh.vertices [nearestVertex];
}
int findNearestVertex(){
Mesh parentMesh=this.GetComponentInParent<MeshFilter> ().mesh;
float smallestDistance = Mathf.Infinity;
int foundVertex=0;
for (int i=0;i<parentMesh.vertices.Length; i++ ){
float distance = Vector3.Distance (transform.position, parentMesh.vertices[i]);
if (distance<smallestDistance) {
smallestDistance = distance;
foundVertex = i;
}
}
return foundVertex;
}
}
While I this script is runnning I change key of parent object in runtime.
If vertex positions are not changin while key is changing, are there another method for my purpose.
Thanks.
Comment