# How can i predict an Orbit?

Hello, Sorry but my english is a mess.
I am trying to Predict and draw the orbit of a rigidbody around another but i cant getit…
If somebody can give me a clue, that be great
The orbital fuction is the same as the natural laws using the phisics included in the engine and works awesome, but i cant draw the orbit, i know how to use the linerenderer component.

what is the function throught time variable to calculate the points?

MASS = Orbiting Object`s mass
RB.mass = Planet Mass.
dir = direction of planet from orbiting object
Distance = Distance between bodies.

RealGravity = ((Gravity) * (RB.mass * MASS)) / (Distance*Distance);

Thanks!

Since your acceleration varies, position in respect to time formula is not that simple, However, you can do a trick to do the job.

You have it’s start position and initial velocity.
From RealGravity * dir and mass, you can find acceleration in the direction of the planet in the launch. So if you consider acceleration CONSTANT for a small change in time, you can find the next position of your LineRender with the formula below;:

S = So + v*t + (a * a * t)/2

The method below will return the Vector3 that you need to assign in your Line Renderer. You choose how many points you will need and how close they will be together from each other. Increase timeInterval for a better approximation

``````Vector3[] TrajectoryPrediction(int points, float timeInterval)
{
Vector3[] final =  new Vector3[points];
final = launch.position;
Vector3 considVel = initialVelocity;//You have this from the impulse force you would add

for(i = 1; i < points;i++)
{
final _= final[i -1] + considVel * timeInterval + (g* g) * dir * timeInterval;_
``````

//g should be a method like your RealGravity used only for this prediction. It will use final[i-1] as the object’s position for the distance and it will be without rb.mass as it will be canceled out when a=F/mass

considVel = considVel + RealGravity * timeInterval;

}
return final;
}
*The script above is not optimized as I am using here to teach a concept