Smooth Quadratic interpolation. [Updated, see my reply in the next lecture :)]

I’ve been trying to solve this for ever but I don’t know how to solve systems of many linear equations in C#.

Basically, I have N waypoints, which are just Vector2 objects, V[0], V[1], V[2], …, V[N-1]

Then I define N quadratic functions for each index i = 0, 1, 2, …, N-1

f_i(t) = (a[i]*t*t + b[i]*t + c[i], x[i]*t*t + y[i]*t + z[i])

The derivatives are simply:

g_i(t) =  (2*a[i]*t + b[i], 2*x[i]*t  + y[i])

where a, b, c, x, y, z are arrays of N floats.

We want that

f_i(0) = V[i]            // so c[i] = V[i].x  and  z[i] = V[i].y
f_i(1) = V[(i+1)%N]      // i.e. f_i(1) = V[0] in the case i = N-1
g_i(1) = g_{(i+1)%N}(0)  // i.e. g_i(1) = g_N(0) in the case i = N-1

This gives 3 constraints for each quadratic, which therefore uniquely defines the solution.

How can I solve a, b, x, y? (c and z are very easy to solve)?

I want this because I want my enemies to smoothly follow curves without ever “teleporting” (discontinuous) but also without ever needing to suddenly change their velocity (although I don’t care if they do change their acceleration discontinuously, that’s tolerable).


Ok I took a different approach: I define a smooth (mathematically smooth) parametric curve using Sine and Cosine functions. This allows me to control the enemy motion beautifully! But it has two weaknesses: it’s very tricky to define a precise route, waypoints just don’t make sense, and it’s hard to control the speed of the enemy, because it can vary as it moves. I will give my script in the next lecture if anyone wants to look at it, copy it, or suggest improvements.

Privacy & Terms