Gravity

Gravity is always an attractive force, which affects the objects by trying to pull them towards each other. According to Newton's formula:

Above 'g' is the gravity constant, 'm1' and 'm2' are the masses of the bodies and 'r' is the distance between the bodies. In other words, the higher the mass, the stronger the force. The shorter the distance, the stronger the force. The force is inversely proportional to the square of the distance.

Because the gravity simulation system follows Newton's laws of motion, one can simulate planet systems and other physical phenomena.

Planets orbiting each other

1. Create two spheres: one near the top edge of the view and another one near the bottom edge of the view.

2. Open the Property Window and set the mass for the both spheres to 100000000 kg. The default 1 kg mass is way too light to generate a noticeable gravity field.

3. Further down on the Phys tab, set the Velocity of the first sphere to '-0.1 0 0' and that of the second sphere to '0.1 0 0'.

Two spheres representing planets

4. Go to the Sim tab and set Gravity to 'Both' for both spheres.

As always, make sure the parent level has its 'Simulation' option set and play the animation.

Set the mass through the 'Phys' tab of the property window

[Note] Note
If the velocities of the spheres are too high, the spheres fly away from each other. If velocities are too low, planets approach each other along a spiral orbit and eventually collide.

Example project: 'tutorprojects/simulation/orbiting_planets'

A three planet system

Let's add a moon to the 'orbiting planet' example created above.

Example project: 'tutorprojects/simulation/three_planets'

1. Rewind the animation back to frame 0. Move the spheres further apart to make room for the moon.

2. Set the velocity of the moon to [-0.35 0 0]. This will prevent the moon from falling into the upper planet. Set the mass to 100 for the moon.

A three planet system. The moon orbits the upper sphere.

3. Go to the Sim tab and make sure that for all spheres gravity is set to 'Both'.

Play the animation. If you defined the masses and velocities correctly, the moon should orbit the upper sphere. Note how both planets affect the orbit of the moon.

Pendulum

Gravity treats all individual objects, such as spheres, as if their entire mass were collapsed to a single point called 'center of gravity'. Because of this, gravity cannot affect the 'spin' property of single objects. Two orbiting spheres will never start to rotate.

You can define non-homogenous mass distributions by constructing objects from several sub objects. For example, you can create a long pendulum object, which will start to oscillate in space because the gravity pulls its ends with different forces.

Let's see how this works:

1. Drag & drop a 0.1 meter grid into the view window to activate grid snapping.

2. Create two heavy spheres with equal masses (100000000 kg, for example)

3. Create a level object consisting of three sub objects: two spheres at the ends and a cylinder connecting the spheres. This is our 'pendulum' object. The pendulum object must be positioned exactly in the center of the two heavy spheres.

The pendulum simulation consists of three objects: two heavy spheres and the pendulum.

4. Rotate the pendulum about its center point slightly (say 30 degrees).

5. Select the two heavy spheres and set Gravity to Cause through the Sim tab of the property window. This way the two heavy spheres affect only the pendulum, but they don't attract each other.

6. Set Gravity to Both for the pendulum.

The rotated pendulum

Turn on Simulation option for the parent level and play the animation. The Pendulum starts to oscillate.

[Note] Note
If you wish to treat an object, which consists of several parts, as a single entity in gravity computations, just define a mass for the whole composite object using the property window's Mass control. The mass value defined by the level overrules its children's mass values. This naturally speeds up the simulation, because only one single point, the center of gravity, is considered. If you have set a mass value for the complete level and later wish to restore the use of child-defined mass distribution, click the Clear button behind the mass control.

Example: 'tutorprojects/simulation/pendulum'

Elastic planet

The previous tutorial demonstrated how gravity affects the spin of hierarchical objects. Gravity can also deform objects (a poor astronaut falling into a black hole can turn to spaghetti).

Example project: 'tutorprojects/simulation/elastic_planet'

1. Create an analytical sphere representing a heavy planet. Set the mass of the sphere to 100000000 kilograms.

2. Create another NURBS or SDS sphere (i.e. a freeform object that allows deformations). Go to the 'Phys' tab and define the following physical properties for it:

As usual, we have to define some initial velocity, which allows the elastic sphere to orbit the heavy sphere. In this case the velocity should be such that it gives a very elliptic orbit for the elastic sphere.

The 'Elasticity' property means that the elastic sphere has internal string forces, which attempt to restore the initial shape. The higher the value, the stronger the string forces are. The result is a 'jelly' like material.

'Rigidity' 0 means that the object can be deformed. For example, warm butter is a good example of a material which can be deformed but which is not elastic. Jelly is an example of an elastic and non-rigid material.

'Rebound Energy' determines how much energy is lost in deformations. If the rebound energy is 1, no energy is lost and the elastic planet would keep jiggling forever. A rebound energy of 0.1 means that jiggling will fade rapidly (due to friction between material particles).

3. Select both spheres and set 'Gravity' to 'Both' through the 'Sim' tab. Then activate 'Simulation' for the parent level.

An elastic object deformed by gravity

Play the animation. The elastic sphere deforms significantly when passing by the heavy sphere.

Birth of a spiral galaxy

Let's create a galaxy, which has a massive black hole in its center.

Example project: 'tutorprojects/simulation/galaxy'

1. Create a small but heavy (100000000 kg) sphere representing the black hole.

2. Use the particle tool to create lots of stars (1D particles) around the black hole.

3. Set gravity for both objects to 'Both'.

4. Set the following physical properties for the particle object:

5. Set the Simulation option for the parent level and play the animation.

The particle object is made completely non-rigid so that gravity can affect each particle as aseparate object. Some initial spin was added for the particles so that they orbit around the black hole instead of falling into it straight away.

[Note] Note
Use a high frame count to preview this animation (say, 1500 frames). After some seconds the particles should form a spiral galaxy. You also may have to increase the Spin value to see the effect.

A spiral galaxy