As part of my coursework for Technical Animation (CMU 15-664),  I simulated cloth behavior from scratch in Unity using C#.

I achieved this  using the Verlet Integration method as described in the paper Advanced Character Physics by Thomas Jakobsen.

Got it to run at around 50 fps. Most GIF examples below have been sped up for the presentation.

  • [above] Basic example of the cloth moving under gravity.

  • The demo runs at around 50 fps real time

  • [above] Cloth moves under gravity, collides with sphere and slips down

  • Used Rigidbodies in Unity to detect the collision; applied force at the point of contact perpendicular to the plane of contact

  • [above] Forcible collision of the sphere with the cloth still under gravity

  • Cloth recovers its shape

  • [above] Another forcible collision of the sphere with the cloth still under gravity

  • [above] If you too fast with the collision, sometimes the sphere goes through the cloth, and things go haywire.

  • [above] Collision with a differently shaped object - a cube

  • [above] Ramming the cube into the cloth, which recovers shape

  • [above] Again, sometimes the cube goes through if the action is done too fast

  • [above] Contact with ground; the two pinned particles are unpinned at some point.

  • [above] Cloth falls on sphere, the ground and slips down under gravity

  • [above] Increased the number of particles from 100 to 400 in this one. The result was considerably slower.

  • [above] Tried to make the cloth collide with itself

  • The Rigidbodies help with collisions among particles

  • [above] Increased the stiffness from 0.5 to 1

  • Some particles are a little off

  • [above] Increased the time step value

  • The cloth sags a little more

  • [above] Reduced the number of iterations form 15 to 1

  • [above] Cloth acting under wind forces; stopped gravity for this one.

Some Notes:

  • Used a procedurally generated mesh in unity

  • Vertices are updated every frame and 

  • Timestep of 0.025

  • Iteration count kept at 15

  • All particles assumed to be of mass 1

  • Stiffness value for particles used as 0.5