Physics Forums Insights
  • Physics
    • Physics Articles
    • Physics Tutorials
    • Physics Guides
    • Physics FAQs
  • Math
    • Math Articles
    • Math Tutorials
    • Math Guides
    • Math FAQs
  • Bio/Chem/Tech
    • Bio/Chem Articles
    • Computer Science Tutorials
    • Technology Guides
  • Education
    • Education Articles
    • Education Guides
  • Interviews
  • Quizzes
  • Forums
  • Click to open the search input field Click to open the search input field Search
  • Menu Menu
unity orbital mechanics

Unity Orbital Mechanics and AR Scaling: Implementation Guide

August 6, 2018/2 Comments/in Computer Science Tutorials, Physics Tutorials/by Russell Patterson
📖Read Time: 4 minutes
📊Readability: Advanced (Technical knowledge needed)
🔖Core Topics: unityscalescalingrigidbodymass

In this Insight I describe implementing basic orbital mechanics simulations in the Unity game engine and an approach to scaling the simulation for Augmented Reality (AR) applications.

Unity is well suited for prototyping and animating physics models. Simulations become more interesting when you can watch interactions over time and see your formulas in action.

Table of Contents

  • Unity Game Engine — Key Points
  • Approach to Orbital Mechanics in Unity
  • Scaling the Solar System for AR
    • Physics mass scaling formula
  • FAQ
    • 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?
    • More Related Articles

Unity Game Engine — Key Points

  1. Unity is a great tool for prototyping games and animating physics models.
  2. Gravity simulations can be an engaging game-design mechanic.
  3. Unity includes built-in physics modules, but they aren’t designed for orbital mechanics out of the box.
  4. The “Gravity and Orbits — Solar System” package can be a useful starting point for an animating solar system.
  5. Generate forces in your update loop using an algorithm (direction, magnitude, combine) and apply them to each object’s Rigidbody component.
  6. You can scale an entire 3D world visually with a single “universe scaler” GameObject, but physics values (mass, initial force, etc.) must also be scaled for AR.
  7. Add a scaling script on each GameObject to scale transform.localScale and the Rigidbody mass (mass must scale with the cube of the scale factor).
  8. Initial speed and position offsets must be scaled as well.
  9. Unity is recommended for physics modeling and animation projects; it supports many platforms and is free to start with.

Unity Solar System

I’ve been developing games for over 30 years and, as a game developer, playing with gravity simulations has been a go-to design mechanic. I’ve always been fascinated by gravity — whether I’m scaling gravity in a game, riding mountain bikes, or shredding at the skatepark.

I recently worked on an AR game prototype that uses orbital mechanics as a gameplay mechanism.

One of the issues with AR is that users must be able to scale models so they appear the appropriate size relative to their real-world location. For example, a virtual object placed in a far corner of a room may look too small from the user’s current position. Conversely, if the open space is too close, the virtual object can appear far too large and spill beyond the display.

In non-AR applications you can set the scale and move the camera to render the scene at the right size. In AR the user is the camera — they physically move closer or farther from the object — so scale and physics both need to adapt at runtime.

Approach to Orbital Mechanics in Unity

Unity’s built-in gravity (a constant downward acceleration) is designed for single-planet scenarios, not multi-body orbital mechanics. To simulate orbiting bodies, you need to compute and apply custom forces to each Rigidbody. The approach I used is:

  1. Generate forces applied to each object (planets/satellites) using:
    1. directionForce = (SunPosition – PlanetPosition) / distance;
    2. forceValue = (SunMass * SatelliteMass) / Math.Pow(distance, 2);
    3. force = GFactor * forceValue * directionForce;
  2. Apply the resulting force to the Unity Rigidbody component with Rigidbody.AddForce().
  3. Let the Rigidbody component determine movement and position updates from the applied forces.
// Example C# sketch: apply computed force to a Rigidbody
void ApplyGravitationalForce(Rigidbody rb, Vector3 force)
{
    if (rb != null)
        rb.AddForce(force);
}

Animated Unity Solar System

Scaling the Solar System for AR

Scaling the visual size of planets is not enough for AR: distances, sizes, masses, and initial velocities must be scaled consistently. A common runtime approach is to avoid relying solely on a single parent “universe scaler” (which changes only transform inheritance). Instead, attach a scaling script to each planet GameObject that:

  • scales the visual model via transform.localScale, and
  • scales the Rigidbody mass by the cube of the scale factor.

Physics mass scaling formula

The physics mass scaling formula is:

newMass = originalMass * scaleFactor3

// 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 speeds and position offsets must scale as well:

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

If you’re using the Gravity and Orbits Solar System package, avoid scaling the initial direction vector — doing so will incorrectly scale initial force magnitudes.

There are many ways to achieve runtime scaling; the approach above worked well for my prototype.

Unity is a great prototyping tool. Adding an animated orbital simulation to your project (PC, Mac, iOS, Android, etc.) makes the system easier to visualize and more engaging. I recommend Unity for modeling and animating physics projects — it’s free to download and straightforward to use.

FAQ

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#. Historically, older Unity versions supported UnityScript (similar to 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 RPGs, FPSs, platformers, and more.

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
    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-01-24 08:17:08Unity Orbital Mechanics and AR Scaling: Implementation Guide
    You might also like
    tcp_ip TCP/IP Protocols for Plug-and-Play Industrial Automation
    AVX-512 registers AVX-512 Assembly Programming: Opmask Registers for Conditional Arithmetic
    processing The Joy of Processing
    algorithms Intro to Algorithms for Programming
    qualitycontrol Hardware, Software, and C Programming Quality Tips
    LCEVC 8k tv LCEVC and EVC: Efficient Video Encoding Guide for 8K
    2 replies
    1. 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 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.

    Trending Articles

    • Explosion-Generated Collapsing Vacuum Bubbles Reach 20,000 Kelvin
    • Explore Some Sins in Physics Didactics
    • It’s Elemental! The Periodic Table Quiz
    • Do Black Holes Really Exist?
    • Grab Bag Science Quiz and Trivia

    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

    astronomy (17) black holes (17) classical physics (35) cosmology (16) education (23) electromagnetism (19) general relativity (19) gravity (24) interview (21) mathematics (39) mathematics self-study (21) Physicist (26) programming (18) Quantum Field Theory (31) quantum mechanics (36) quantum physics (24) relativity (40) Special Relativity (16) technology (19) universe (21)
    2026 © Physics Forums, ALL RIGHTS RESERVED - Contact Us - Privacy Policy - About PF Insights
    • Link to X
    • Link to Facebook
    • Link to LinkedIn
    • Link to Youtube
    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