Simulating gravitational attraction between bodies I'm currently working on a simple simulator in Unity3D that involves planets orbiting each other. I wrote the following C# script to do that. It uses the classic gravitational formula, 

$$F=G\frac{m_1m_2}{r^2}$$

using UnityEngine;

/// &lt;summary&gt;
/// Class used for calculating
/// how an object orbits another
/// object.
/// &lt;/summary&gt;
/// &lt;param name="parentObject"&gt;The parent gameObject to orbit.&lt;/param&gt;
/// &lt;param name="objectMass"&gt;The mass of the object.&lt;/param&gt;
/// &lt;param name="gravityConstant"&gt;The gravitational constant.&lt;/param&gt;
[RequireComponent(typeof(Rigidbody))]
public class OrbitObject : MonoBehaviour 
{
    public OrbitObject parentObject;
    public float objectMass;
    public float gravityConstant;

    private Vector3 parentPosition;
    private float parentMass;

    /// &lt;summary&gt;
    /// Calculates the gravitational attraction.
    /// &lt;/summary&gt;
    /// &lt;returns&gt;The force to apply&lt;/returns&gt;
    Vector3 CalculateGravitationalForce()
    {
        this.parentPosition = this.parentObject.transform.position;
        Vector3 force = this.parentPosition - transform.position;
        float distance = force.magnitude;
        float strength = (this.gravityConstant * this.parentMass * this.objectMass) / (distance * distance);
        force.Normalize();
        force = force * strength;
        return force;
    }

    /// &lt;summary&gt;
    /// FixedUpdate is run once per frame.
    /// FixedUpdate is used so that calculations
    /// don't need to be multiplied by Time.deltaTime.
    /// &lt;/summary&gt;
    void FixedUpdate()
    {
        rigidbody.AddForce(this.CalculateGravitationalForce());
    }

    /// &lt;summary&gt;
    /// Start this instance.
    /// &lt;/summary&gt;
    void Start()
    {
        this.parentPosition = this.parentObject.gameObject.transform.position;
        this.parentMass = this.parentObject.objectMass;
    }
}


For those who are curious, a gif of the script in action can be found here.
Just a note on your commenting:

Should you be breaking XML comments up across lines like that?

/// &lt;summary&gt;
/// Class used for calculating
/// how an object orbits another
/// object.
/// &lt;/summary&gt;


I feel that should be three lines:

/// &lt;summary&gt;
/// Class used for calculating how an object orbits another object.
/// &lt;/summary&gt;


Likewise, I feel that the following comment:

/// &lt;summary&gt;
/// FixedUpdate is run once per frame.
/// FixedUpdate is used so that calculations
/// don't need to be multiplied by Time.deltaTime.
/// &lt;/summary&gt;


Could be rewritten as:

/// &lt;summary&gt;
/// FixedUpdate is run once per frame.
/// &lt;/summary&gt;
/// &lt;remarks&gt;
/// FixedUpdate is used so that calculations don't need to be multiplied by Time.deltaTime.
/// &lt;/remarks&gt;


Personally, I think breaking comments along multiple lines like that makes it harder to read. You're eyes have to jump to unnatural places.

Likewise, the &lt;remarks&gt; bit is nice because those comments aren't shown in Intellisense, but they can still be placed in the generated XML documentation files.

The only other bit I would mention, is the use of this. You should either use it consistently, or try to limit it. Sometimes (especially in larger cases) it helps to clear things up. But if you use it for some of the properties and not others, it can have a negative impact.

I'm referring to the following:

Vector3 CalculateGravitationalForce()
{
    this.parentPosition = this.parentObject.transform.position;
    Vector3 force = this.parentPosition - transform.position;
    float distance = force.magnitude;
    float strength = (this.gravityConstant * this.parentMass * this.objectMass) / (distance * distance);
    force.Normalize();
    force = force * strength;
    return force;
}


Where does transform.position come from? The fact that you use this on all the other properties/fields of the class but not that one throws confusion into the mix. It's not a local variable, that much is true. But where exactly does it come from, is a little harder to notice right out of the box.

Again, these are all suggestions. Whether or not you like/use them is up to you, but this is how I would write it out.