• 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 /
  • Help Room /
avatar image
0
Question by pauladam316 · Jan 26, 2016 at 04:07 PM · orbitplanets

Planetary Gravity and improper orbits

Hey everyone! I have started working on creating orbits in unity using planetary gravity. using UnityEngine; using System.Collections;

 public class PlanetaryGravity : MonoBehaviour {
 
     GameObject planet;
 
     // Use this for initialization
     void Start () {
         planet = GameObject.FindGameObjectWithTag("Planet");      
     }
     
     // Update is called once per frame
     void FixedUpdate () {    
         GetComponent<Rigidbody>().AddForce(((planet.transform.position - transform.position).normalized)  * 364500.487f, ForceMode.Acceleration);
     }
 }

this is put on my satellite. I also have another script that does this

 GetComponent<Rigidbody>().velocity = (new Vector3(0,0,7676f));

this should, in theory put the satellite in an elliptical orbit around the center object, tagged planet. Instead it does this.

https://www.youtube.com/watch?v=LZRmQA3qRbM&feature=youtu.be

It makes this strange pattern that makes me think that the orbital path is rotating around the center as the object orbits. Any idea what may be causing this?

Comment
Add comment · Show 4
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 NoseKills · Jan 26, 2016 at 04:35 PM 0
Share

Are you doing the latter just once or in FixedUpdate?

To me it looks like the 'gravity' is just too strong and the object falls into an elliptical orbit.

Whatever the reason, I must warn you that the physics engines used in games and Unity aren't mathematically exact (floating point inaccuracy, some engines have limitations on maximum speed/size of objects due to performance or practical reasons) and you probably can't make stable solar system unless you keep correcting the orbit radius in FixedUpdate()

avatar image pauladam316 NoseKills · Jan 26, 2016 at 04:51 PM 0
Share

The velocity is set once in Start(). I understand that with strong gravity it will fall into an elliptical orbit, but it should still return to its original spot right? the fact that its making this pattern makes me think that this isn't physics accuracy issues and is something wrong with my logic

avatar image NoseKills pauladam316 · Jan 26, 2016 at 05:29 PM 0
Share

Depends completely on the force and velocity you use. If you freeze the video in the first frame, you can see that the gravity you apply is such that after passing the center of orbit for the first time, the object drops farther below the x-axis than where it left from. If you add a bit more velocity the object might pass the gravitational center from farther away and drop less during the first pass.

Even real planets have such rotating elliptical orbits

avatar image incorrect · Jan 26, 2016 at 05:38 PM 0
Share

Btw, if you are using numbers like 364500.487f, I would suggest you reading Unity - Coordinates, Scales and creating huge games. ;)

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by incorrect · Jan 26, 2016 at 05:12 PM

Did not you noticed your formula for gravity is wrong?

Gravity works like this: alt text

Your force mode is also wrong.


gravity-formula.jpg (9.3 kB)
Comment
Add comment · Show 1 · 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 pauladam316 · Jan 26, 2016 at 05:52 PM 0
Share

Thanks! I was thinking that I only needed to calculate gravity using that equation for accurate orbits, but without it the force of gravity does not increase as distance decreases. It works now though. Thanks!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How do i make so the player rotates when the camera does? 2 Answers

Example of Procedural Planet generation? 3 Answers

Moving forward based off of Rotation 3 Answers

Input.GetTouch(0).deltaPosition for rollout on orbit camera behaving strangly 0 Answers

Calculating world position from depth buffer; is there a better solution? 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