Quantcast
Channel: Questions in topic: "tree"
Viewing all articles
Browse latest Browse all 513

Tree vertices never change position in wind

$
0
0
I am trying to access the vertices of a tree created with the unity tree creator. The tree is placed in a wind zone and moves correctly according to the wind. However, I want to use the vertices of the mesh for attaching an object their position so that is follows the movement of the tree. But the vertices never change value in the array list, even though they move visually. How can this be? void Awake () { tree = GameObject.FindGameObjectWithTag("Tree"); treeMesh = tree.GetComponent().mesh; float closestDistance = 99999; for(int i = 0; i < treeMesh.vertices.Length; i++){ float tempDistance = Vector3.Distance(transform.position, treeMesh.vertices[i]); if(tempDistance < closestDistance) { closestDistance = tempDistance; closestIndex = i; } } } void Update () { transform.position = tree.transform.TransformPoint(treeMesh.vertices[closestIndex]); }

Viewing all articles
Browse latest Browse all 513

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>