Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 Jun 22
sparklines
Close Help
  • 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
1
Question by Lunprod · Aug 03, 2015 at 04:05 AM · rigidbodyorbittrajectoryplanetspaceship

How to predict orbit based on time?

How can I predict a spaceship's orbit, as the player adjusts the velocity. Let's say the spaceship is in a circular orbit. How do I predict the future XYZ coordinates for that and also for elliptical orbits. Say the player fires the engines to boost the speed. How do I continuously update the orbit?

I can find tons of formulas on Kepler's and Newton's laws but none of them are for the future XYZ positions.

I know Kerbal Space Program predicts trajectories using a function of time but they don't say the formulas they use.

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 Nerevar · Aug 03, 2015 at 08:16 AM 0
Share

People usualy work in spherical coordinates to resolve such a system, you only need to use the newton gravitation equation (it is an acceleration expression so you need to integrate it 3 times)

I could not find the right example on the internet at this point.

avatar image Lunprod · Aug 03, 2015 at 02:40 PM 0
Share

yeah, I'm using Newton's universal law of gravitation to add a force towards the planet and adding a horizontal (relative to the planets surface) force to make the satellite orbit.

Here's the script that does that:

 public float g = 6.674f * (10^-11);
 private float massSatellite;
 public float massPlanet;
 private float r;
 public GameObject Planet;
 public Rigidbody rbObject;
 public Rigidbody rbPlanet;
 public Vector3 dist;
 private float gravitationalForce;
 public float initialForce;
 private Vector3 gravityOfPlanet;
 public float gravitationalAcceleration;


 void Awake() 
 {
     rbObject = GetComponent<Rigidbody>();
     rbPlanet = Planet.GetComponent<Rigidbody>();

 }

 void Start()
 {
     massPlanet = rbPlanet.mass;
     massSatellite = rbObject.mass;
     rbObject.AddForce (new Vector3 (initialForce, 0, 0), Force$$anonymous$$ode.Impulse);
 }


 

 void FixedUpdate()
 {


     dist = Planet.transform.position - transform.position;
     r = dist.magnitude;
     gravitationalForce = (g * massPlanet * massSatellite) / (r * r);

     rbObject.AddForce(-dist * gravitationalForce); //maybe add Forecemode.acceleration
      

 }



What I would like to do is predict the orbit using a linerenderer and a for loop.

avatar image Lunprod · Aug 03, 2015 at 03:53 PM 0
Share

I actually just replaced the initial force with an initial velocity vector if that would make things easier.

avatar image Ederitosss Lunprod · Feb 09, 2016 at 11:02 AM 0
Share

Can you find an answer to your question?, i have the same problem...

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by PeterMu · May 30, 2016 at 04:44 PM

Hi,

I have just completed a blog post on this topic: http://nbodyphysics.com/blog/2016/05/29/planetary-orbits-in-javascript/

It explains how to use the Kepler equations and provides sample Javascript code.

If you want an "out of the box" solution, you can take a look at my new asset "Gravity Engine" in the asset store: https://www.assetstore.unity3d.com/en/#!/content/62432

PM

[1]: https://www.assetstore.unity3d.com/en/#!/content/62432

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

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.

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

Simulating 2D planetary gravity and trajectpry using Unity 0 Answers

Ellipticall Orbit like Spaceflight simulator 1 Answer

Can you pls help me fix this rigidbody collision problem 0 Answers

RigidBody movement with AddForce 3 Answers

I have a planetary gravity script; how do I make the object speed up? 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