Unity WebGL Player | Cloth Physics
Summary : The Cloth Physics Simulation is a system of particles, much like boids, that are connected and create force based on neighboring particle’s position. The rules and relationships between the particles is what change the functionality. The main thing that connects each particle in the cloth simulation are spring dampers.The spring damper generates forces that are then applied to the particles in addition to previous forces and gravity. After using the spring dampers to simulate a cloth, additional features can be applied such as aerodynamic forces, pulling, and tearing.
Part 1: Gravity Particles are spawned in a grid of 10 x 10 resulting in 100 different particles. Each particle has its own specific velocity, and sum of forces that can change its position over time. The first type of force that is being applied is one of the simplest forces in physics, gravity. Gravity in this simulation, is described as a constant -10 unit/second^2 on the Y plane. This force is applied to all particles evenly, and continuously. Gravity in my implementation is also multiplied by a coefficient, which corresponds to a slider that allows the user to change the coefficient at runtime.
Part 2: Spring Dampers The main thing that makes the particles act like a cloth, is the way that the spring dampers act with each other, and add forces to the corresponding particles. The spring damper consists of a spring constant, a damping factor, a rest length, and two particles. Spring constant is the strength of the spring. The damping factor is the factor that stands for the fluidity of movement between the springs. The rest length is the length that the full spring damper will always try to go pull itself to. Each of these equations have a coefficient that change the strength of each factor. The combination of these factors are what create the realistic looking simulation. The equations use distances and velocities. The combined vectors are converted into 1 dimension, used to compute spring force, and then mapped back into 3D and spread to the particles. Each particle has a spring damper with each of its immediate neighbors. This gives a springiness to the cloth.
Part 3: Aerodynamic Forces After the regular cloth physics are added, I chose to add aerodynamic forces to the cloth. In order to do this, you have to create a surface for the “wind” to hit. In my implementation, I made triangles so that I could have a surface to push forces against so that I can have a surface normal. After the equation of the wind and its strength is calculated, the force is divided by 3 and separated amongst the 3 particles in the triangle.
Part 4: Pulling and Tearing I also added the ability to use the mouse and click and drag a selected particle. This will usually bring the problem that a normal cloth would most likely tear. It was actually quite simple to implement. If two particles, that have a spring damper together, were pulled too far apart, the spring damper will destroy itself. The particle will then pop off of the cloth. Forces are then no longer calculated for the particle that gets popped off.