- Home /

# calculate the future position of an object in orbit

I'm developing a game that relies on some basic orbital physics, they don't have to be exact but a close approximation would be nice. yes, a nice and tidy Kepler orbit.

I used newtons law *-(G M m)/r* and a unit vector *{x,y,z}/ √(x^2 + y^2+z^2)* to add a force to a Rigidbody, which works marvelously, but I want to draw the orbit (using a series of point coordinates across the orbital path and joining them with a line renderer) so the player can accelerate/decelerate and see it adjust it in real-time. (and then just make the ship follow that orbit path because it would save a lot of processing power)

I have done loads of research and I can't seem to find a formula that will work without the semi-major axis or the total orbit time while explaining whats going on in an understanding manner. could one of you geniuses out there please help me out? I don't just want just the equation(i could just download a gravity plugin from the app store if I didn't want to learn), It would be nice to learn how it all fits together and how it works :)

**Answer** by Bunny83
·
Sep 05, 2019 at 10:44 AM

Well determining the orbital parameters from the state vectors is not that trivial as the state vectors essentially just encode the derivative of the motion equation,

Though you probably can bring everythnig together piece by piece. You can determine the semi-major axis length from the orbital energy of the object

You can use the dot product to determine if you currently accelerate (moving closer to the central body) or if you decellerate (moving away from the central body). So you know on which side of the ellipse you are. Just do

```
if (Vector3.Dot(velocity, vectorToCentralBody) > 0){
// accelerate
} else {
// decellerate
}
```

Maybe that will help you to get your equation finished ^^

Note while calculating the exact theoretical orbit certainly is helpful, it might not give you what your time discrete simulation is giving you in the end. This is due to being time discrete and having to deal with numerical imprecision which can accumulate over time. If you just want a relatively short prediction ahead, it's often simpler to just "fast forward" your simulation and see where you end up. This is the most accurate predition of what **your simulation** will actually do.

But shouldn't there be a way to calculate a future point with just state vectors? Like spaceflight simulator does? (once I have it in 2d it should be relatively easy to tilt its plain in the 3rd dimension) I literally just want to draw the orbital path/trajectory. And then I won't have to use the solution I'm currently using, rather, I just make the ship go towards the next point in the orbital path or trajectory. That way I wouldn't have to deal with impressions in my orbit prediction as such because in a sense the object would "follow its prediction"

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.