Tutorial 1 – Binary Stars

Create an GravityEngine (GameObject/3D Object/GravityEngine)

Move two copies of the Star prefab into the scene

Place them at X=-10 and X =10

Press PLAY and observe

The gravity engine moves the objects and they go through each other and fly apart. This is due to a numerical breakdown when they get very close and the forces become large. In most cases a collision handler would intervene.

There is an alternative algorithm that is less vulnerable to this. It can be found under the GravityEngine/Advanced section in the inspector. Select HERMITE8 and see what happens. (Hermite adapts the time step and does a better job with large forces when objects get close. It used more CPU than LEAPFROG but does a better job of conserving energy).

Create an orbiting pair by setting the Y velocity of the NBody component of one star to +4 and the other to -4.

PLAY now shows these objects in orbit around each other as a binary pair.

Getting a specific orbit by setting the velocity is challenging

Create an empty game object “BinaryPair”

Attach the Script “BinaryPair”

Make each Star a child of the binary pair

Set the size (semi-major axis) of the ellipse to 20. Now the inspector shows BOTH orbits and they can be adjusted.

Make one of the stars a different mass – notice how the orbits are adjusted.

The game speed of the binary star evolution can be controlled in several ways:

The mass of each star could be scaled. Larger mass values result in larger forces and faster motion.

The mass scale of the entire scene is controlled by the Gravity Engine. In the Scaling section of the GravityEngine the overall mass scale can be adjusted with the ‘mass scale’ parameter. Increasing the mass scale will make everything move faster. Velocities will also be adjusted so the same motion results – just faster.

GravityEngine also allows control of the timescale. This changes the motion speed but by doing more physics calculations each frame.