Particle System
Particle systems can be used to simulate many objects and phenomena in games, animation and VR. Smoke, water, flame, explosions, plus cloth and plants.
A basic particle system involves a set of objects moving under individual motion.
Each particle is updated each frame. Each particle moves independently of the others. The motions can be fairly arbitrary.
Beyond a basic particle system, you can start adding features:
a) Collisions so the particles collide with each other and the scene.
b) Forces so the particles move under a physics simulation.
Forces can be environmental (gravity, wind, explosion),
from other particles (spring model in cloth, gravity between particles),
or artificial (flocking, attraction to fixed patterns.)
The Nature of Code has a reasonable introduction to particle systems.
https://natureofcode.com/book/chapter-4-particle-systems/
Unity supports a built-in particle system, and user-created ones.
https://learn.unity.com/tutorial/introduction-to-particle-systems#6025fdd9edbc2a112d4f0133
But, sometimes the built-in functions are not enough.
Case Study
Three Body (Gravity)
Solar System (Gravity)
Flocking (Boids)
Gravity
The mechanisms of Newton's law of universal gravitation;
a point mass m1 attracts another point mass m2 by a force which is proportional to the product of the two masses and inversely proportional to the square of the distance (r) between them.
Regarcless of masses or distance, the magnitudes of |F1| and |F2| will always be equal. G is the gravitational constant,.
This is not about teaching you physics.
It is about practicing how to interpret and translate it into computation,
and how to translate those models into the digital world.
Coding in Unity
Create a project that simulates Three body Problem
Let’s list the variables we need to simulate gravity between two objects.
Let there be...
Unity - Scripting API: GameObject.CreatePrimitive (unity3d.com)
Try different primitive types too.
struct BodyProperty
{
public float mass;
public Vector3 velocity;
public Vector3 acceleration;
}
Vector functions in Unity (you can find them from the most of the engines)
Unity - Scripting API: Vector3.Normalize (unity3d.com)
Unity - Scripting API: Vector3.magnitude (unity3d.com)
Unity - Scripting API: Vector3.sqrMagnitude (unity3d.com)
Unity - Scripting API: Vector3.Lerp (unity3d.com) - not using this time but useful
Three to N-body
Three-body problem - Wikipedia
In physics, specifically classical mechanics, the three-body problem is to take the initial positions and velocities (or momenta) of three point masses orbiting each other in space and then to calculate their subsequent trajectories using Newton's laws of motion and Newton's law of universal gravitation.[1]
Unlike the two-body problem, the three-body problem has no general closed-form analytic solution.[1] The differential equations that govern the motions of three gravitating bodies are not integrable and cannot be solved to give explicit formulas for the positions of the bodies as a function of time. For most initial conditions, the dynamical system for three orbiting bodies is chaotic, and the only way to predict their motions is to estimate them using numerical methods.
The three-body problem is a special case of the n-body problem. Historically, the first specific three-body problem to receive extended study was the one involving the Earth, the Moon, and the Sun.[2][3] In an extended modern sense, a three-body problem is any problem in classical mechanics or quantum mechanics that models the motion of three particles.
Mini Task (Part of the assignment #1)
Create a 3 body problem simulation (5 points)
Overall Assignment #1 will include the Solar System
Did you experience Error? What would be the reason?
Acceleration doesn't update.. spheres disappeared.. sphere's position doesn't change...
Another consideration is efficiency.
If you have a large number of particles and are computing intersections or focus between them, the brute force approach is O(N^2).
(What is the exact number?)
A data structure or algorithm is needed to speed that up.