Well, let's explain it this way:
With the aforementioned
y = a(x - cx)^2 + h, you know...
y is where the parabola's height will be, given all of the other information.
a is the amount the parabola is scaled by.
x is where it will be, horizontally.
cx is the amount the parabola is offset by on the x-axis (where the vertex x is). Note that it is being subtracted. That means that if you want a negative offset, you will actually be adding (or subtracting a negative, same thing).
h is the amount it's being moved up or down. Also where vertex y is.
Keep in mind, the equation for a quadratic (what makes a parabola) can also be modeled by
ax^2 + bx + c = y.
The vertex (highest/lowest point on the parabola) can be gotten by:
Code: Select all
function GetVertex( a, b, c )
local x = ( -b ) / ( 2 * a )
local y = c - ( ( b ^ 2 ) / ( 4 * a ) )
return x, y
end
Note that y also represents the height of the vertex.
You can get the roots of the parabola with:
Code: Select all
function GetRoots( a, b, c )
local Discriminate = b^2 - 4 * a * c
if Discriminate < 0 then return nil end -- If it's negative, it doesn't intersect.
local x1 = ( -b + math.sqrt( Discriminate ) ) / ( 2 * a )
local x2 = ( -b - math.sqrt( Discriminate ) ) / ( 2 * a )
return x1, x2
end
The vertex will always be halfway between the two, so now we have three main points:
x1, x2, and vx (Vertex x )
x1 is where the boss is (x position).
x2 is where the player will be (player.x + player.velocity * TIME).
vx is the center of the parabola.
vx will be
( x1 + x2 ) / 2.
vy is
vx + Height.
y = a * ( vx - x1 ) * ( vx - x2 ), therefore:
a = ( vy ) / ( ( vx - x1 ) * ( vx - x2 ) )
b = a * ( x1 + x2 )
c = a * x1 * x2
and y = ax^2 + bx + c
bartbes wrote:(This is the point where someone else comes in and gives you a solution that's easier to calculate and/or program.)
Not sure explaining yours a bit more and giving other options counts as a
better solution or not...
EDIT: And yes, having different y positions makes this formula a bit more complicated. Lemme see if I can figure that out.