# How to orbit an object around another object in an oval path in Unity?

I would like to create kind of planetary orbit structure for my game. I was used transform.RotateAround(Vector3.zero, Vector3.forward, RotationAngle * Time.deltaTime); and it rotates in a circular shape. But I would like to do it in an oval (Ellipse) shape.

You may translate the orbiting object with the coordinates of an elliptical path. You can get the x and y values from the equations.

x = centerX + (semi-major * sin T)

y = centerY + (semi-minor * cos T)

Use some code like below:

float alpha = 0f;

void Update ()
{
//transform.position = new Vector2(center.x + (semiMajor * Mathf.Sin(AngleX)),
//                                 center.y + (semiMinor * Mathf.Cos(AngleY)));

transform.position = new Vector2(0f + (10f * Mathf.Sin(Mathf.Deg2Rad * alpha)),
0f + ( 5f * Mathf.Cos(Mathf.Deg2Rad * alpha)));
alpha += 5f;//can be used as speed
}


Result with a trail renderer: More generalized solution:

Formula used:

x = centerX + {semi-major * cos(alpha)*cos(tiltAngle) - semi-major * sin(alpha)*sin(tiltAngle)}

y = centerX + {semi-minor * cos(alpha)*sin(tiltAngle) + semi-minor * sin(alpha)*cos(tiltAngle)}

public float alpha = 0f;

public float tilt = 45f;

void Update ()
{
transform.position = new Vector2(0f + (10f * MCos(alpha) * MCos(tilt)) - ( 5f * MSin(alpha) * MSin(tilt)),
0f + (10f * MCos(alpha) * MSin(tilt)) + ( 5f * MSin(alpha) * MCos(tilt)));
alpha += 5f;
}

float MCos(float value)
{
}

float MSin(float value)
{