How To Make Quadratic Bezier Curve Through 3 Points

My code:

private Vector3 GetPointInPath(Vector3 playerPos, Vector3 netPosTop, Vector3 aimPos, float t)
{
   float r = 1f - t;
   return (r * r * playerPos) + (2f * r * t * netPosTop) + (t * t * aimPos); 
 }

Any idea how to make Bezier Curve go through netPosTop, instead of being controlled by it?

You just can’t because there are infinitely many bezier curves that will go through those 3 points. Keep in mind that if you have point A, B and C and your curve should start at A and end at C and go through B, the curve could start and end at various angles and stil go through B. So there’s not a single solution for this problem. Have a look at this interactive Desmos drawing. I placed the middle control point at a position so the curve goes through the point B I have defined. Just try moving the middle control point around and you find infinitely many positions which all make your curve pass through point B.

Of course you could specify some constraints and extra conditions. However calculating the position of the middle conrol point is not that trivial depending on your extra conditions. For example if you want your thrid point being at t == 0.5 you can calculate the position of the middle control point by:

B = 2*yourPointOnTheCurve − 0.5f*A−0.5*C;

You simply get that equation by plugging in 0.5 into the bezier equation and solving for B.

p(t) = (1-t)² * A + 2f *(1-t) * t * B + t * t * C
// plug in 0.5 and define that p(0.5) == yourPointOnTheCurve
yourPointOnTheCurve = 0.25 * A + 0.5 * B + 0.25 * C
// solve for B
yourPointOnTheCurve - 0.25 * A - 0.25 * C =  0.5 * B
2*yourPointOnTheCurve - 0.5 * A - 0.5 * C =  B

And there you have your answer. Of course if the point you want your curve to go through is extremely close to the first or last point you will get very weird curves since, remember, that point is at t==0.5. So the curve is bend too much. Here’s an example

edit

Based on my comments below you can create some helper methods like this:

// untested code
public static Vector2 CalculateMiddlePoint(Vector2 aStart, Vector2 aEnd, float aTime, Vector2 aPoint)
{
    float t = aTime;
    float rt = 1f-t;
    return 0.5f*(aPoint - rt*rt*aStart - t*t*aEnd) / (t*rt);
}

public static float CalculateMiddleTime(Vector2 aStart, Vector2 aEnd, Vector2 aPoint)
{
    float a = Vector2.Distance(aPoint, aStart);
    float b = Vector2.Distance(aPoint, aEnd);
    return a / (a+b);
}

public static Vector2 CalculateBestMiddlePoint(Vector2 aStart, Vector2 aEnd, Vector2 aPoint)
{
    return CalculateMiddlePoint(aStart, aEnd, CalculateMiddleTime(aStart, aEnd, aPoint), aPoint);
}

Using CalculateBestMiddlePoint and passing your two endpoints as the first and second argument and your third point as last parameter, this method should calculate the “best fitting” middle control point for your curve.

@Bunny83 What happens if K is 1?