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

VR transform tree mesh on axe hit

$
0
0
I'm lost. I want to deform a tree-mesh on an axe hit, at the position of the collision. How would this be possible? Mesh manipulation? Fake-holes? Shaders?

So far I tried it with moving the vertices, which can be seen in this gif:

https://imgur.com/a/KEfS5EQ

What I did to achieve that:

- Find closest vertex to hit.point (raycast) - Find all triangles containing this point (+highlight them) - Find all vertices on a horizontal plane (the same level as the first found vertex) - Take those (3) vertices and assign them some velocity, code example (pseudo):

vertexVelocities = new Vector3[mesh.vertices.Length]; [...] Vector3 point = hit.point; point += hit.normal * forceOffset; foreach vertex on same level { Vector3 pointVertex = vertex - point; float attenuatedForce = force / (1f + pointVertex.sqrMagnitude); float velocity = attenuatedForce * Time.deltaTime; vertexVelocities[index] += pointVertex.normalized * velocity; displacedVertices[i] += vertexVelocities[index] * (Time.deltaTime); mesh.SetVertices(displacedVertices.ToList()); }

Problems can be seen in the gif.
I think I need to create more triangles at the position of impact, to get a higher resolution, but how? Also, the direction of the vertex movement is not quite right. Also, the vertices are poking out of the tree... Is this even a "good" approach? Maybe someone here has an idea to improve that, or even an alternative way of handling the issue.

Some help would be *greatly* appreciated.

Viewing all articles
Browse latest Browse all 513

Trending Articles



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