2D ORBITAL PROJECTION WOES

I am making a 2D Newtonian physics game. One of the main aspects of the game is orbits. I want to have a projection line which will project the players trajectory. I have one set up but it does not accurately predict the orbital pattern. Instead, the prediction line shoots off and doesn’t circle the body.

Here is a photograph of my predicament. The magenta line is the orbit (it was traced out by the Debug). The dark teal line at the bottom right quadrant that juts out is the prediction. Notice that the prediction is sort of on point at first but does not encircle the planet, instead jutting out into infinite away from the planet

Here is my code for the prediction line:

public class OrbitPredictionLine : MonoBehaviour
{

    private Vector2 uV;

    public void DrawTraject (Vector2 startPos, Vector2 startVelocity )
    {
        //line rendering..
        int verts = 2000;
        LineRenderer line = GetComponent<LineRenderer>();
        line.SetVertexCount(verts);

        //input vars

        Vector2 pos = startPos;
        Vector2 vel = startVelocity;

        GameObject orbitedPlanet = GameObject.FindGameObjectWithTag("BeingOrbited");
        uV = orbitedPlanet.GetComponent<PlanetaryGravity>().uV;

        Vector2 grav = uV;

        for (var i = 0; i < verts; i++)
        {
            line.SetPosition(i, new Vector3(pos.x, pos.y, 0));
            vel = vel + grav * Time.fixedDeltaTime;
            pos = pos + vel * Time.fixedDeltaTime;
        }
}

void Update () {

        Vector2 wotanPos = GameObject.Find("Wotan").GetComponent<Rigidbody2D>().transform.position;

        DrawTraject(wotanPos, GameObject.Find("Wotan").GetComponent<Rigidbody2D>().velocity);


    }
}

Wotan is the name of the ship. uV is the gravitational force vector.

i think this is what you are looking for

Hi there! Welcome to rocket science!

Effectively what you need to do is take the current velocity vector, and predict where the object will be the next frame. Then do some maths on the predicted position, get a new vector, and predict the position of the object the frame after that, and so on and so on, until you hit your limit (I use “frame” as a unit of time, how far you predict for each point is variable). You would then draw your line along those predicted points.

You should be able to do everything you need with only circular motion, but the other links will also provide other useful information.

Here are several links you should look at: