|
1 | 1 | # unity-harmonics
|
2 | 2 | Harmonic Motion in Unity.
|
| 3 | + |
| 4 | +## Project Status |
| 5 | +- This project is still in its **very** early phase. I plan to make this project into a cloth engine to be used in games and for industrial purposes. |
| 6 | + |
| 7 | +## Planned Features |
| 8 | +- Higher-Order ODE Integrator (RK4) For more accurate Velocity, Position, and Acceleration calculations |
| 9 | +- Separation of Spring objects from Body objects for more freedom of usage and simpler construction of spring-mass based meshes and structures |
| 10 | +- Self-Collisions and collisions with geometric meshes for spring-mass based meshes |
| 11 | +- Switching to double-precision mathematics for more precise positions with little to no performance loss |
| 12 | + |
| 13 | +## Setup |
| 14 | + |
| 15 | +1. Clone the Repo |
| 16 | + |
| 17 | +``` |
| 18 | + git clone https://github.com/sandalconsumer/unity-harmonics.git |
| 19 | +``` |
| 20 | +2. Open it in the Unity Hub |
| 21 | + |
| 22 | +- Open Unity Hub |
| 23 | +- Click on the **Add Project** button in the top right next to **New Project**. |
| 24 | +- This project was made with Unity 6000.1.1f1 so that is where the code is guaranteed to work, but most Unity 6 versions will (most likely) work well. |
| 25 | + |
| 26 | +## Documentation |
| 27 | + |
| 28 | +There are 2 main scripts you need to know to understand this repo. And they are: |
| 29 | +1. Body |
| 30 | +2. Simulation Data Compiler |
| 31 | + |
| 32 | +The **Body** script is added to the gameObject you want to simulate a spring system with, and the **Simulation Data Compiler** visualizes the data from the bodies. |
| 33 | + |
| 34 | +### Body Variables |
| 35 | +- Data Compiler is the **Simulation Data Compiler** script that will read the data from the current Body. |
| 36 | +- Mass is the mass of the point (the GameObject's transform's position) in kilograms. |
| 37 | +- Connected Springs is a list of all the springs that will Influence the current Body. Currently, the only way to make new springs that the body will recognize is to access this, but I am planning to make a dedicated GameObject for springs in the near future. |
| 38 | + |
| 39 | +### Simulation Data Compiler Variables |
| 40 | +- Plot Scale is a scalar that controls the size of the graph in the unity scene. |
| 41 | +- Plot origin is where the graph will start putting points down in the unity scene. |
| 42 | + |
| 43 | +## Notes / Technical Details |
| 44 | +- The ODE Integrator used for the point-masses in this simulation is currently Velocity Verlet. I might add RK4 as an option in the future. |
| 45 | +- I am planning for this project to be my graduation project, which means that I will most likely be working on it for the next 1.5 years. |
| 46 | +- Floating-point numbers are currently used for this simulation, but I am planning to switch to Double-Precision soon by bringing in **DVector3** from my other project **unity-n-body**. |
| 47 | + |
| 48 | +## Simulation Flow |
| 49 | +On Simulation Start: |
| 50 | +1. Initialize all positions for point-masses from preset transform |
| 51 | +2. Calculate initial stretch of all springs |
| 52 | + |
| 53 | +Every Timestep: |
| 54 | +1. Represent Springs in Unity Scene using Debug |
| 55 | +2. Velocity Verlet's Half-step (for Second-Order Accuracy) |
| 56 | +3. Recalculation of spring forces and stretching based on new positions from Velocity Verlet's intermediate step |
| 57 | +4. Final Step of Velocity Verlet |
| 58 | +5. Sending Data to Simulation Data Compiler |
| 59 | + |
| 60 | +## Credits |
| 61 | + |
| 62 | +[oPhysics Interactive Physics Simulations on SHM](https://ophysics.com/w1.html) |
| 63 | +[Wikipedia Restorative Force of springs from Hooke's Law](https://en.wikipedia.org/wiki/Hooke's_law) |
| 64 | +[Arcane Algorithm Archive's Verlet Integration Documentation](https://www.algorithm-archive.org/contents/verlet_integration/verlet_integration.html) |
0 commit comments