# Rocket game orbit problems *URGENT*

I’m making a rocket game. I have made faux gravity and the gravity works fine. So I went on to make gravity and drag get less as you go up. Theoretically, after you have 0 drag and a little bit of gravity you should orbit. But the rocket did not orbit?!!?. Please tell me how to make the rocket orbit.

Here is the Code for gravity and such:

``````public Transform _Planet;
public float Gravity;
public Rigidbody rocket;
public Transform rocketT;
public float DistanceEarth_;
public float atmosHeight;
public bool oneOver = true;
public bool twoOver = true;
public bool threeOver = true;
public bool fourOver = true;
public bool fiveOver = true;
public bool SphereOF_influ_out = true;

// Update is called once per frame
void Update()
{
DistanceEarth_ = Vector3.Distance(rocketT.position, _Planet.position) - 246601.54f;
if (DistanceEarth_ < atmosHeight / 5)
{
Gravity = 30;
rocket.drag = 2;

}
if (DistanceEarth_ > atmosHeight / 5 &&DistanceEarth_ < (atmosHeight / 5) * 2  )
{
Gravity -= Gravity / 5;
rocket.drag -= rocket.drag / 5;
oneOver = false;
}
if (DistanceEarth_ > (atmosHeight / 5) * 2 && twoOver && DistanceEarth_ < (atmosHeight / 5) * 3)
{
Gravity -= Gravity / 4;
rocket.drag -= rocket.drag / 4;
twoOver = false;
}
if (DistanceEarth_ > (atmosHeight / 5) * 3 && threeOver && DistanceEarth_ < (atmosHeight / 5) * 4)
{
Gravity -= Gravity / 3;
rocket.drag -= rocket.drag / 3;
threeOver = false;
}
if (DistanceEarth_ > (atmosHeight / 5) * 4 && fourOver && DistanceEarth_ < (atmosHeight / 5) * 5)
{
Gravity -= Gravity / 3f;
rocket.drag -= rocket.drag / 3f;
fourOver = false;
}

if (DistanceEarth_ > atmosHeight && fiveOver && DistanceEarth_ < (atmosHeight / 5) * 6)
{

rocket.drag -= rocket.drag;
Gravity -= Gravity / 3f;
fiveOver = false;
}

if (DistanceEarth_ > atmosHeight * 50)
{
Gravity -= Gravity;
SphereOF_influ_out = false;

}

}
``````

your planet is rotating right? so you can resume it on a single (simplified) calculus

`````` //about Rocket
public Rigidbody rocket;
public float DistanceEarth_;
public float rocketMass;
public Transform rocketT;
public Transform _Planet;
public float GravityOnSurface;
public float surfaceToCenter = 246601.54f;//distance from center to surface
public bool SphereOF_influ_out = true;
//used to check rotation of active planet
public vector3 prevForward = Vector3.zero;

void Start(){
prevForward = _Planet.forward;
}

// Update is called once per frame
void Update()
{
Vector3 totalForce  = vector3.zero;
//ditance to the center? otherwise change it to measure the distance to center on your scene
DistanceEarth_ = Vector3.Distance(rocketT.position, _Planet.position) - 246601.54f;
//if your planet rotation is constant, better store it on planet script, to not do it every frame
Vector3 tangentRot = (_Planet.forward-prevForward)*Time.DeltaTime;

float fCentripetal = (tangentRot.sqrMagnitude / DistanceEarth_)*rocketMass;
float fGravity = GravityOnSurface * (surfaceToCenter/DistanceEarth_)*(surfaceToCenter/DistanceEarth_);

//multiply the forces by their respective direction vectors
//(maybe this can be optimized on some way doing all together using vectors?)
Vector3 totalForce = fCentripetal*tangentRot.normalized + fGravity * (_Planet.position - rocketT.position).normalized;
you can ignore the gravity force when is very low, to evade unnecessary calculations (`fGravity` is reduced by squared proportional distance, `fCentripetal` is linear, at some point you start just rotating, at other, far point from the first, planet just can’t drag you enough to be measured)