Physics Forums Insights
  • Physics
    • Mechanics
    • Thermodynamics
    • Electromagnetism
    • Fluids
    • Optics
    • Particles
    • Quantum
    • Relativity
    • Biophysics
  • Astronomy
    • Astrophysics
    • Cosmology
    • Observing
  • Mathematics
    • Algebra
    • Analysis
    • Geometry
    • Number Theory
    • Probability
  • Computing
    • Programming
    • Electronics
    • Imaging
  • Science Culture
    • Education
    • Careers
    • Philosophy
    • Profiles
    • Trivia
  • Forums
  • Click to open the search input field Click to open the search input field Search
  • Menu Menu
unity orbital mechanics

Simulating Orbital Mechanics in Unity for AR Apps

August 6, 2018/2 Comments/in Computer Science Tutorials, Physics Tutorials, Programming/by Russell Patterson
📖Read Time: 5 minutes
📊Readability: Moderate (Standard complexity)
🔖Core Topics: Unityforcemassscalegravity

Orbital mechanics can be simulated in the Unity game engine by replacing its built-in single-planet gravity with a custom force calculation applied to each Rigidbody every update, then scaling both the visual model and its physics mass together so the simulation still behaves correctly when resized for Augmented Reality (AR) viewing.

Table of Contents

  • Key Takeaways
  • Why does orbital mechanics matter for AR applications?
  • How do you simulate multi-body gravity in Unity?
  • How do you scale a solar system simulation for AR?
    • Physics mass scaling formula
  • Is Unity a good tool for physics simulation projects?
  • Frequently Asked Questions
    • What is the Unity Game Engine?
    • What platforms does Unity support?
    • How much does Unity cost?
    • What programming languages does Unity use?
    • What types of games can I create with Unity?
    • Why can’t I just use Unity’s built-in gravity for a solar system simulation?
    • Why does mass need to scale by the cube of the scale factor rather than linearly?
    • More Related Articles

Key Takeaways

  • Unity’s default gravity system applies a constant downward acceleration and cannot handle multi-body orbital physics without custom code.
  • A custom force script uses the formula force = GFactor * (SunMass * SatelliteMass / distance²) * directionForce, applied via Rigidbody.AddForce().
  • When resizing objects for AR, Rigidbody mass must scale by the cube of the scale factor, not linearly with the visual size.
  • The author has worked as a game developer for over 30 years and used this orbital mechanics technique in an AR game prototype.
  • Unity’s “Gravity and Orbits — Solar System” package is a usable starting point for building an animated solar system.
  • Initial velocity and position offsets need their own scaling step; scaling only the direction vector will distort the resulting force magnitude.

Why does orbital mechanics matter for AR applications?

In a standard, non-AR application, a developer can fix the scale of a scene and move the camera to frame it correctly. AR removes that option because the user’s own movement acts as the camera. A virtual object placed in a large room can look too small from the user’s starting position, while the same object in a tight space can appear oversized and spill past the edges of the display. Because the user physically walks closer or farther away, both the visual scale and the underlying physics have to adjust in real time rather than being set once at the start.

I recently built an AR game prototype that used orbital mechanics as its core gameplay mechanic, and solving this scale problem was the main technical challenge.

How do you simulate multi-body gravity in Unity?

Unity’s built-in gravity module is designed for a single gravitational source, such as a character falling toward the ground, not for multiple orbiting bodies pulling on each other. To simulate that, each object’s force has to be calculated manually and handed to Unity’s physics engine every frame. The approach used in this prototype follows three steps:

  1. Calculate a direction vector and force magnitude for each planet or satellite: directionForce = (SunPosition − PlanetPosition) / distance, and forceValue = (SunMass × SatelliteMass) / distance².
  2. Combine these into a single force: force = GFactor × forceValue × directionForce.
  3. Apply that force to the object’s Rigidbody component using Rigidbody.AddForce(), then let Unity’s physics engine handle the resulting movement and position updates.
// Example C# sketch: apply computed force to a Rigidbody
void ApplyGravitationalForce(Rigidbody rb, Vector3 force)
{
    if (rb != null)
        rb.AddForce(force);
}

Unity’s “Gravity and Orbits — Solar System” package can serve as a starting point for an animated solar system built around this same force-calculation loop.

How do you scale a solar system simulation for AR?

Scaling only the visual size of each planet is not enough for AR, because distance, mass, and initial velocity all have to scale together or the orbits will break. Relying on a single parent “universe scaler” GameObject only changes transform inheritance; it does not touch the physics values driving the simulation. Instead, each planet GameObject needs its own scaling script that adjusts both its visual transform and its Rigidbody mass.

Physics mass scaling formula

Rigidbody mass must scale by the cube of the scale factor, since mass is a volumetric property: newMass = originalMass × scaleFactor³.

// scale the model's transform (appearance) and its mass
void UpdateScale(float scaleFactor)
{
    transform.localScale = originalScale * scaleFactor;

    // scale the mass using the original mass stored at initialization
    Rigidbody rb = this.GetComponent<Rigidbody>();
    if (rb != null)
    {
        // Use stored originalMass (must be saved when object initialized)
        rb.mass = originalMass * Mathf.Pow(scaleFactor, 3);
    }
}

Initial speed and position offsets need the same treatment, applied separately from mass:

satellite.GetComponent<InitialSpeed>().speed = InitialSpeedConstant * scaleFactor;
Vector3 position = centerPlanet.transform.position + positionOffset * scaleFactor;

If you are building on the Gravity and Orbits Solar System package, avoid scaling the initial direction vector on its own. Doing so scales the initial force magnitude incorrectly, since direction and force magnitude need to stay proportionally linked.

There are multiple valid ways to implement runtime scaling in Unity; the transform-plus-mass approach described above worked well for this AR prototype.

Is Unity a good tool for physics simulation projects?

Unity is well suited to prototyping and animating physics models because it lets a developer watch interactions unfold over time and see formulas play out visually rather than as static numbers. Adding an animated orbital simulation to a Unity project, whether targeting PC, Mac, iOS, or Android, makes the underlying system easier to visualize and more engaging for players. Unity is free to start with and runs across a wide range of platforms, which makes it a practical choice for this kind of modeling work.

Frequently Asked Questions

What is the Unity Game Engine?

Unity is a cross-platform game engine developed by Unity Technologies. It is used to create games and interactive content for web, desktop, consoles, and mobile devices.

What platforms does Unity support?

Unity supports a wide range of platforms including Windows, macOS, iOS, Android, Xbox, PlayStation, and Nintendo Switch.

How much does Unity cost?

Unity is available in several tiers. The Personal (free) plan is available for individuals and small businesses that meet the revenue limits. Pro and other paid tiers require a subscription fee.

What programming languages does Unity use?

Unity primarily uses C#. Older Unity versions supported UnityScript, which resembled JavaScript, and Boo, but modern Unity development should be done in C#.

What types of games can I create with Unity?

Unity can create many types of 2D and 3D games, including role-playing games (RPGs), first-person shooters (FPSs), platformers, and more.

Why can’t I just use Unity’s built-in gravity for a solar system simulation?

Unity’s built-in gravity applies a single constant downward force meant for scenarios like a character falling to the ground. Orbital mechanics requires multiple bodies exerting force on each other based on mass and distance, which means the forces must be calculated manually in code and applied to each Rigidbody rather than relying on Unity’s default gravity setting.

Why does mass need to scale by the cube of the scale factor rather than linearly?

Mass corresponds to volume, and volume scales with the cube of a linear dimension. If an object’s visual size doubles in each direction, its volume, and therefore its mass, increases eightfold. Scaling mass linearly instead of by the cube would make the physics simulation behave inconsistently after resizing.

Russell Patterson
Russell Patterson

I’ve been developing games for over 30 years and as a game developer.

More Related Articles

  • All About the Einstein Field Equations
    Tags: programming, technology, Tutorial, Undergraduate
    Share this entry
    • Share on Facebook
    • Share on X
    • Share on WhatsApp
    • Share on LinkedIn
    • Share on Reddit
    • Share by Mail
    https://www.physicsforums.com/insights/wp-content/uploads/2018/08/unity_orbital_mechanics.png 135 240 Russell Patterson https://www.physicsforums.com/insights/wp-content/uploads/2019/02/Physics_Forums_Insights_logo.png Russell Patterson2018-08-06 16:16:142026-07-31 13:05:51Simulating Orbital Mechanics in Unity for AR Apps
    You might also like
    renormalization Quantum Renormalisation Made Easy
    computermath Why Can’t My Computer Do Simple Arithmetic?
    Mitochondria When did Mitochondria Evolve?
    birktheo Learn A Short Proof of Birkhoff’s Theorem
    Fourier Series Riemann Zeta Function Computing the Riemann Zeta Function Using Fourier Series
    cpu programming Parallel Programming on a CPU with AVX-512
    2 replies
    1. aaroman
      aaroman says:
      August 17, 2018 at 1:41 am

      Similar: https://compphys.go.ro/newtonian-gravity/ but in C++ with OpenGL. Using Velocity Verlet.

      Log in to Reply
    2. jedishrfu
      jedishrfu says:
      August 6, 2018 at 8:43 pm

      Great insight! I especially liked the description of scaling factors and how they a codependent on one another requiring a more nuanced program design.

      Unity is awesome, we did a unity simulation of Challenger Deep where the user could fly through the canyon using an Oculus Rift for one implementation and similar code for an Android tablet implementation.

      Log in to Reply

    Leave a Reply

    Want to join the discussion?
    Feel free to contribute!

    Leave a Reply Cancel reply

    You must be logged in to post a comment.

    Popular Articles

    • What Planck Length Is and It’s Common Misconceptions
    • Learn Interacting Quantum Fields in Mathematical Quantum Field Theory
    • Quantum Renormalisation Made Easy
    • The Block Universe – Refuting a Common Argument
    • Why You Can’t Quantum Tunnel Through a Wall
    • How to Measure Internal Resistance of a Battery
    • Can We See an Atom?
    • The Balloon Analogy Explained: Cosmic Expansion Without a Center
    • Lenses and Pinholes: What Does “In Focus” Mean?
    • Big Bang Evidence: CMB, Redshift & Element Abundances

    Physics Forums

    • Classical Physics
    • Atomic and Condensed Matter
    • Quantum Physics
    • Special and General Relativity
    • Beyond the Standard Model
    • High Energy, Nuclear, Particle Physics
    • Astronomy and Astrophysics
    • Cosmology
    • Other Physics Topics

    Receive Insights Articles to Your Inbox

    Enter your email address:

    Blog Information

    • Become a Member!
    • Write for Us!
    • Table of Contents
    • Blog Author List

    Popular Topics

    black holes (23) classical physics (35) education (23) FAQ (58) General (230) general relativity (23) Graduate (185) gravity (25) Guide (86) interview (49) mathematics (39) mathematics self-study (21) Physicist (26) Quantum Field Theory (34) quantum mechanics (36) quantum physics (24) relativity (40) Special Relativity (22) Tutorial (147) Undergraduate (287)
    2026 © Physics Forums, ALL RIGHTS RESERVED - Contact Us - Privacy Policy - About PF Insights
    • Link to X
    • Link to Facebook
    • Link to LinkedIn
    Link to: Why the Quantum | A Response to Wheeler’s 1986 Paper Link to: Why the Quantum | A Response to Wheeler’s 1986 Paper Why the Quantum | A Response to Wheeler’s 1986 Paperwhy quantumLink to: Intuitive Black‑Scholes Options Pricing Explained Simply Link to: Intuitive Black‑Scholes Options Pricing Explained Simply stock options mathIntuitive Black‑Scholes Options Pricing Explained Simply
    Scroll to top Scroll to top Scroll to top