Result with a trail renderer:
[![enter image description here][1]][1]
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 Vector3(0f + (10f * Mathf.Cos(Mathf.Deg2Rad * alpha) *
Mathf.Cos(Mathf.Deg2Rad * tilt)) -
(5f * Mathf.Sin(Mathf.Deg2Rad * alpha) *
Mathf.Sin(Mathf.Deg2Rad * tilt)),
0f + (10f * Mathf.Cos(Mathf.Deg2Rad * alpha) *
Mathf.Sin(Mathf.Deg2Rad * tilt)) +
(5f * Mathf.Sin(Mathf.Deg2Rad * alpha) *
Mathf.Cos(Mathf.Deg2Rad * tilt))
);
alpha += 5f;//use this to control speed
}
You can control tilt of the eliptical path with the above code. Constants can be changed as you need.
[1]:
https://i.sstatic.net/cqmVn.png