how do i make bezier curve handles dynamic?

first, I don’t understand this bezier curve stuff that i am using too much, so if you can show me an easier aproach suitable to my situation, that would be very awesome.

I was out fishing for a tutorial on bezier curves and I eventually found one and I ended up with this script:

    public LineRenderer line;
    public Transform start;
    public Transform end;
    public Transform handle1;
    public Transform handle2;
    
    private float c;

    private Vector3 h1;
    private Vector3 h2;
    private Vector3 q0;
    private Vector3 q1;
    
    void Start () {
        q0 = CalculateBezierPoint(c, start.position, handle1.position, handle2.position, end.position);

        line.SetVertexCount(100);
        c = 0.0f; //for first curve c is set to 0
        for (int i = 0; i < 99; i++)
        {
            c += 0.01f;
            q1 = CalculateBezierPoint(c, start.position, handle1.position, handle2.position, end.position);
            if (i == 0) line.SetPosition(i, q0);
            line.SetPosition(i + 1, q1);
            q0 = q1;
        }
    }

    public Vector3 CalculateBezierPoint(float t, Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3) {

        float u, uu, uuu, tt, ttt;
        Vector3 p;

        u = 1 - t;
        uu = u * u;
        uuu = uu * u;
        tt = t * t;
        ttt = tt * t;

        p = uuu * p0;
        p += 3 * uu * t * p1;
        p += 3 * u * tt * p2;
        p += ttt * p3;

        return p;
    }

As you might be able to see, this aproach is using 2 handles to calculate the bezier points. (I really don’t know if I need that much I only want to have one single curve in my line. This is the part where I think it could be done more easily)

I need to have the handle(s) dynamic. so that the start and end object can move around in the scene and would still have the line connecting them. I tryed around some hours, but I only got straight lines. Wich faced me to another problem that also needs to be addressed…

…My World isn’t a plane, but a sphere:
56926-untitled.png
So I need this line to always be outside (around) this sphere.

It also might be necessary to make the LineRenderer Size (VertexCount) dynamic, So I won’t run into later performance issues.

I feel like this is too much to ask for or that this isn’t the right place. If I should put this into the forums please tell me so. :\

I think you can do this without beziers. All you are doing is mapping a linerenderer around a sphere with Vector3.Slerp.

Example project

SphericalLines.cs

Snap Transforms will position the From and To transforms on the sphere. You may want to turn that off for your game. It’s useful for playing around with handles in the editor though. It’ll update the LineRenderer in the editor so you see what you do. If you don’t want that, remove [ExecuteInEditMode].