This page looks best with JavaScript enabled

Deforming a Mesh at Runtime Based on Collisions with Unity

 ·   ·  ☕ 2 min read

Time to start working on deforming our dynamically generated mesh. We’re going to be working on a physical simulation that deforms the mesh when things hit it. The advantage to this is that we will be able to modify our mesh as objects impact it causing them to make dents when they hit it or lines as they are dragged across it.

For reference we’re going to be using the snow simulated in Tomb Raider which deforms as your feet drag through it. We aren’t to the human interacting with it stage yet but that’s what we’re building towards. For now we’re going to stay simple and basic. Either a mesh is deformed or not and each physics collision causes the mesh to be deformed.

This will require modifications to our mesh being sent in realtime back to the Mesh to render. To do that we’ll maintain two in memory array lists. One to store the original position so we can maintain the mesh data and track how much a vertex has changed and the second will be used to track the current vertices of the mesh - the manipulated vertices - which will be used for actually rendering our mesh.

The MeshDeformer code can be found on GitHub:

The PhysicsDeformer code is available on GitHub and you can get it here:

Sam Wronski
Sam Wronski
Maker of things, currently helping build cloud things @ Microsoft. World of Zero is a personal project disconnected from my professional work. Lets make something awesome together!