Runtime Mesh Deformation in Unity (Footsteps, Damage, Softbody Physics)

Runtime Mesh Generation in Unity (Complete Guide)
Runtime Mesh Generation in Unity (Complete Guide)
June 29, 2026
Procedural Cave Generation in Unity (Cellular Automata Method)
Procedural Cave Generation in Unity (Cellular Automata Method)
June 29, 2026
Runtime Mesh Generation in Unity (Complete Guide)
Runtime Mesh Generation in Unity (Complete Guide)
June 29, 2026
Procedural Cave Generation in Unity (Cellular Automata Method)
Procedural Cave Generation in Unity (Cellular Automata Method)
June 29, 2026

Runtime Mesh Deformation in Unity (Footsteps, Damage, Softbody Physics)

Runtime mesh deformation allows developers to modify 3D meshes during gameplay. This technique is commonly used for features like footprints in snow, terrain damage, bullet impacts, and soft body physics.

Instead of using pre-made animations, the mesh itself is modified in real time, creating more dynamic and interactive environments.


How Meshes Work in Unity

A mesh in Unity is defined by several components:

  • Vertices – the points that define the shape
  • Triangles – how vertices are connected
  • UVs – texture coordinates
  • Normalslighting direction

To deform a mesh, we modify the vertex positions at runtime.


Accessing Mesh Vertices

First we need to access the mesh and its vertices.

Mesh mesh;
Vector3[] vertices;

void Start()
{
    mesh = GetComponent<MeshFilter>().mesh;
    vertices = mesh.vertices;
}

Now we can modify the vertex positions dynamically.


Example: Footsteps in Snow

A common example of mesh deformation is footprints in snow or sand.

When the player steps on the surface, nearby vertices are pushed downward.

public void AddFootstep(Vector3 worldPosition, float radius, float depth)
{
    for(int i = 0; i < vertices.Length; i++)
    {
        Vector3 worldVertex = transform.TransformPoint(vertices[i]);

        float distance = Vector3.Distance(worldVertex, worldPosition);

        if(distance < radius)
        {
            float falloff = 1 - (distance / radius);
            vertices[i].y -= depth * falloff;
        }
    }

    mesh.vertices = vertices;
    mesh.RecalculateNormals();
}

This creates a smooth footprint indentation.


Example: Bullet Damage

Mesh deformation can also simulate damage from explosions or bullets.

public void ApplyDamage(Vector3 hitPoint, float radius, float force)
{
    for(int i = 0; i < vertices.Length; i++)
    {
        Vector3 worldVertex = transform.TransformPoint(vertices[i]);

        float distance = Vector3.Distance(worldVertex, hitPoint);

        if(distance < radius)
        {
            Vector3 direction = (worldVertex - hitPoint).normalized;
            vertices[i] += direction * force;
        }
    }

    mesh.vertices = vertices;
    mesh.RecalculateNormals();
}

This pushes nearby vertices outward, creating a crater or dent effect.


Soft Body Mesh Deformation

For soft objects like jelly or rubber, vertices can move dynamically based on physics forces.

Each vertex behaves like a small spring that tries to return to its original position.

Vector3[] originalVertices;
Vector3[] velocities;

void Start()
{
    mesh = GetComponent<MeshFilter>().mesh;
    vertices = mesh.vertices;

    originalVertices = mesh.vertices;
    velocities = new Vector3[vertices.Length];
}

Now we apply spring forces.

void Update()
{
    for(int i = 0; i < vertices.Length; i++)
    {
        Vector3 displacement = vertices[i] - originalVertices[i];

        velocities[i] -= displacement * 5f * Time.deltaTime;
        velocities[i] *= 0.9f;

        vertices[i] += velocities[i] * Time.deltaTime;
    }

    mesh.vertices = vertices;
    mesh.RecalculateNormals();
}

This produces a soft body wobble effect.


Optimizing Mesh Deformation

Runtime mesh modification can be expensive if done incorrectly.

  • Cache vertex arrays
  • Only update vertices near the interaction point
  • Use lower vertex density meshes
  • Use Unity Jobs + Burst for large meshes

Common Use Cases

  • Footprints in snow or sand
  • Explosion craters
  • Destructible environments
  • Soft body objects
  • Interactive terrain

Games Using Runtime Mesh Deformation

  • Red Faction (destructible terrain)
  • Teardown
  • No Man’s Sky
  • SnowRunner

These games use mesh manipulation techniques to create highly interactive environments.


Final Thoughts

Runtime mesh deformation is a powerful technique that makes environments feel reactive and alive.

By directly modifying mesh vertices at runtime, developers can create dynamic effects like footprints, damage systems, and soft body physics.

When combined with procedural generation and physics systems, mesh deformation can dramatically increase immersion in your game world.


Leave a Reply

Your email address will not be published. Required fields are marked *


Skip to toolbar