Custom Gravity
Gravity Engine 1.4 allows the force law used by the gravity engine to be changed/customized. This produces new and interesting orbits which do not return to their original position – since this a property unique to Newton’s force law (as well as F = R^2).
For example a scene with a force law of 1/R results in orbits such as:
This force can be selected via the Gravity Engine inspector:
You are not limited to the force laws as defined in the inspector. By selecting custom and adding a component implementing the IForceDelegate interface you can define any radial force law. For example with the CustomForce delegate:
public class CustomForce : MonoBehaviour, IForceDelegate {
public float a = 2.0f;
public float b = 1.0f;
/// <summary>
/// acceleration = a * ln(b * r)
/// </summary>
/// <returns>The accel.</returns>
/// <param name="m2">M2.</param>
/// <param name="r_sep">R sep. The distance between the bodies</param>
public double CalcF(double r_sep) {
return a*System.Math.Log(b*r_sep);
}
public double CalcFdot(double r_sep) {
return a * b/r_sep;
}
}
The resulting orbits are:
Note that the IForceDelegate class has both the force law and it’s derivative Fdot (or jerk, as the change in acceleration is sometimes called). The Fdot is used if the Hermite integrator is selected. It can be omitted if only the Leapfrog integrator is used.