As in the title, I can figure out the formula of **float T**.

The idea is that the camera follows the target and is always parallel to it, but also want the camera respects the curve. I know T is **→** `float t = something / curveLength`

but I don’t know the **something**

I have the *position* of **P1**, **P2**, **Tan** (Green circle), **Camera** and **followTarget** (Orange diamond).

Also can follow with complex forms.

Well this is a non-trivial problem and depending on the actual requirements doesn’t have a direct solution. First of all you should clarify what you mean by “parallel”. Only lines can be parallel. So if you have another line that line could be parallel to the tangent line on the curve. Maybe you want the camera to be at a 90° angle to the curve? Maybe you want it at the closest point on the curve? Maybe some other linear projection (onto the x or y axis? So the camera and point should have the same x or y coordinate?)

Next question is, do we only talk about 2d or 3d? 2d makes a lot things a bit easier. Unrelated to the coordinate space, do we only talk about a single quadratic bezier curve? Or do consider using cubic bezier curves (or even higher degree) as well?

Just to illustrate the problem: The quadratic bezier equation is of course a quadratic polynomial. To find the closest point on the curve we need to construct the distance equation in relation to t. This will turn the equation into a polynomial of degree 4. In order to find the minimum we need the first derivative of that equation which would give us a cubic equation that need to be solved. While this is doable it’s not that simple. However if we talk about a cubic bezier, the distance equation would be a polinomial of degree 6 and the first derivative an order 5 polynomial. There is simply no direct solution to solve such an equation. However there are iterative approximation algorithms. Over here you can find some reference material. Though keep in mind that a polynomial of degree 3 has 3 potential solutions and degree 5 of course 5 potential solutions. So it’s still up to you to pick one of the solutions that fits your requirements.

As I said, this was just an example when we talk about finding the closest point on the curve. While a quadratic bezier is relatively simple, a cubic or higher degree allows self-intersection and overlapping which will create many ambigous situations which can not be solved mathematically but may requires additional state tracking to find the most reasonable solution.

The two examples you’ve shown doesn’t seem to match any of the above mentioned casaes. Your camera is not at the position 90° to the curve, it isn’t aligned on x or y and it’s not at the closest point on the curve. So to me it’s not really clear whether the images you’ve shown illustrate actual examples or if they should just explain the situation. In any case I think you should clarify what exact behaviour you’re expecting.

ps: If you’re just look for a reasonable position on the curve for a certain player position, for quadratic bezier curves using the projected position between the start and end point of the curve as normalized “t” should work reasonably well, especially when the player moves around. The closest point in your second example would probably not behave that well.