This project was born out of my desire to experiment, learn, and improve as a programmer. Since I have an interest in physics in video games, I decided to create an implementation of a softbody simulation using code in Unity.
Step 1 - Investigation: What is a Soft-body?
"Soft-body dynamics is a field of computer graphics that focuses on visually realistic physical simulations of the motion and properties of deformable objects (or soft bodies)."
                                                                                                                                                                                             -Wikipedia
Once I understood what a soft-body was, I began researching how to create one, and I came across the game "JELLYCAR." Its main mechanics are based on soft-body physics, and thanks to Walaber Entertainment's video, I started grasping the practical aspects of soft-body behavior.
​​​​
I continued my research and found a video by Gonkee, which helped me fully understand how I could integrate a soft-body physics simulation into my code.
The video explained how each edge/face of the object is formed by nodes that are connected to each other through springs. By applying Hooke's law, we can measure the spring force and, consequently, adjust the stiffness and damping of the soft-body.
Once the Hooke's law was researched and the logic behind a soft-body was understood, we began with the implementation and testing within Unity.
Step 2 - Integration & Testing
First, I conducted a test using Unity components to learn how it worked in a real scenario. (I used Configurable Joint, Spring Joint, and a Rigidbody for each node).
Once I understood the functioning, I created the first version of the code to simulate a rope. Although it worked, I wasn't satisfied with its unstable behavior. As a solution, I decided to use the Fixed Joint component, which allows connecting one object to another through its Rigidbody, ensuring that the rope's elements didn't separate.
It was a good start, but it wasn't what I wanted. Therefore, by modifying the initial code, I began my first tests in 3D.
The code was designed to make the figure modular so that I could observe the behavior of each node. Each node of the figure calculates the spring force in relation to its adjacent nodes.​​​​​​​
Note: You must manually add the adjacent nodes to the public list (AdjacentNodes), and the code will connect the initial node with the nodes in the list and perform all the calculations.
I continued with tests on objects of different shapes and sizes to improve the visual aspect. Although I managed to create a functional 2x2 cube, I realized that using Unity's Fixed Joint severely limited the soft-body's behavior.
However, I discovered that the Fixed Joint component worked exceptionally well for creating horizontal springs.

Even though it looked good, it wasn't exactly what I was aiming for. To achieve a fully functional soft-body, I modified the code once again, this time utilizing the Spring Joint component. Drawing on the knowledge I had gained from previous experiments, I was able to create a perfectly functional soft-body with the added benefit of being modular.
I will leave the code modular, allowing you to experiment with different shapes. The project is free to use but if you use it, don't forget to mention me :)

Check the code on my GitHub.
Back to Top