In this repository, I have implemented some Ordinary Differential Equations (ODE) solvers and cloth particle system that use them. They basically do something like this:
X is a vector that contains all particle's positions and velocities. The job of ODE solvers is to update this vector at every small time step. To do this they need function that returns derivative at needed moment of time.
This function can be found at ParticleSystem
class as well as X vector. Simple example of how this configuration can be used in Update()
method: stepper.takeStep(system, Time.deltaTime);
. stepper is an instace of some
ODE solver class and system is an instance of Particle system descendant. With positions information you can draw particles and generate meshes.
The ODEsolvers
file contains 3 classes. They all realize ODEsolver interface.
- ExplicitEuler - high speed, low precision
- Trapezoidal - medium speed, medium precision
- RungeKutta4 - low speed, high precision
There are 2 ways:
- import
ParticleSystems.unitypackage
via Assets-Import Package - clone/download this repository and move the
Assets/Scripts/ParticleSystems
folder to your Unity project's Assets folder
I've only presented two use cases: pendulum and cloth physics. But this system can be extended to:
- Cables
- Hair
- Sof-body
- Liquids
It's worth noting that computing now takes place on the CPU. For full utilization I should move the calculations to the GPU 🥴
Thank you for reading this 😊!