• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by mattbarton.exe · Apr 25, 2012 at 10:49 PM · physicsrigidbodyspaceplanets

How do you calculate gravity from planets in a solar system?

Hi, all. I'm trying to create a "Gravity Wars" type game where you have a solar system and all of the heavenly bodies (including the sun) have gravitational fields. So when you fire a missile in one location, its trajectory is affected by the heavenly bodies it passes nearby.

What functions of Unity should I be looking at to try to calculate multiple sources of gravity from all those different (and moving) bodies?

It's a 2D game, which should (I hope) make this a lot simpler.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

6 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by chusmaverde · Apr 06, 2020 at 10:20 AM

It has been a long time since this has been answered, but maybe I can give some additional info.

The basic idea is to use Newton's Gravitational pull, as mentioned by other comments. Other answers give some links to basic code on how to solve that.


Solution


I have created a blog entry that solves this issue: Physics-based solar system lessons. It explains:

  • The math used.

  • The problems found (precision issues, orbit prediction, Speeding up the system)

  • The implementation code (and basic setup)

  • Where to find accurate planetary data.


Here you can see an example of the applied code in the blog in a Earth-Moon system with a couple of satellites (orbiting Earth and Moon). alt text

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by kaedmon · Jan 01, 2013 at 03:08 AM

For any developers out there who would like to implement this really easily, try out:

World Physics System ~ http://nimbusgarden.com/worldphysicssystem

The World Physics System is a celestial body & point gravity scripting interface for Unity, intended as a replacement for the stock downward gravity. WPS can be used to simulate planetary orbits, body-body attraction, or "snowballing" effects. You may use it to create spherical worlds "out-of-the-box," but World Physics System is implemented robustly and is lightweight, providing you complete freedom in expressing your point gravitation creativity, complex and repulsive forces, allowing you to use the system as a subcomponent for other effects, such as spells, powerups, or goal-based Artificial Intelligences for NPC's. With the WPS, the sky is truly the limit!

Available from the Unity Asset Store, here.

More information, here.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by pudd1nG · Apr 26, 2012 at 02:42 AM

Check out this script for a great example of simple planet gravity. http://www.unifycommunity.com/wiki/index.php?title=Simple_planetary_orbits

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by aldonaletto · Apr 26, 2012 at 02:07 AM

Take a look at this question: http://answers.unity3d.com/questions/196749/objects-acting-under-each-others-gravity.html

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by bompi88 · Apr 26, 2012 at 12:52 AM

Additional: Search wikipedia for "Newton's law of universal gravitation". With an adjusted gravitational constant and mass (that fits your world´s metric system) you can loop between the nearest planets (and for example the sun with its high gravitational drag), and calculate the gravitational force, then the object´s acceleration and velocity. But you don`t want to calculate this for hundreds of objects each update, maybe per 5-10 th update? You can try and see what you get.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
  • 1
  • 2
  • ›

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Artificial Gravity 2 Answers

Player in Spaceship 2 Answers

Child rigidbody acting strange when moving parent. 0 Answers

Rigidbody gravity between planets 1 Answer

Ping Pong bat is not detecting the collision with the wall 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges