SOLVED Parabolic path between two objects

Geners

Member
I'm looking to find a formula that describes a parabolic arc between two points with a specified vertex.

I have a card object that I want to arrive in a specific location but I want it to arc there.

I thought about just using the normal polynomial form and setting the x coordinates of the card and the destination as x-intercepts

and this works... If they both begin on the same y coordinate and I can't specify a vertex.


Is there a way I can get this effect? I tried googling but nothing was quite what I was looking for.
 
Last edited:

Geners

Member
I'm also thinking about about having the card and the destination be two points of a circle and just rotating the card along the circle until it gets to the destination but I'm not sure if that would look right.
 
I'm looking to find a formula that describes a parabolic arc between two points with a specified vertex.
Not too sure what you imply by "specific vertex".
From what I'm understanding, you are looking to solve the function y = ax2+bx+c
When you plug y=0 and solve that, you will get the two intersecting points of a parabolic.
The "slope" of that function is going to be your "a" and "b" (maybe that's the vertex you are referring to?), and the crossing point along the y axis on x=0 is going to be your "c"

Warning: High Scool flashback incoming!
x#1 = (-b + √b2 – 4ac)/2a
x#2 = (-b – √b2 – 4ac)/2a
 
Last edited:

Geners

Member
Not too sure what you imply by "specific vertex".
From what I'm understanding, you are looking to solve the function y = ax2+bx+c
When you plug y=0 and solve that, you will get the two intersecting points of a parabolic.
The "slope" of that function is going to be your "a" and "b" (maybe that's the vertex you are referring to?), and the crossing point along the y axis on x=0 is going to be your "c"

Warning: High Scool flashback incoming!
x#1 = (-b + √b2 – 4ac)/2a
x#2 = (-b – √b2 – 4ac)/2a
I want my card object to move from its starting point to an endpoint in an arc and it needs to pass through a height that I set. I know how the quadratic formula works, and I don't think this is what I'm looking for as the two points I need it to pass through are on varying heights.

The height I need the card to pass through I was going to represent as the vertex.
 
Last edited:
This is exactly what you need, it's just that you wont be able to solve it using y = 0, you will have to plug in your specific points if they are on different heights.
Think of it this way: you have starting point, end point, "gate-point#1" and "gate-point#2". You have all you need to find "a" and "b" from those x's and y's.
There would be 2 solutions, but one will be shaped like a "u", which I assume is not what you want.
But yeah, it's more of a hassle the way you're setup than solving for the same crossing point (tho it's a matter of sitting on it for half and hour, to DIY, really).
You may check GMLscripts.com, maybe there's already something that does just this on there (not sure, but doesn't hurt to look)

EDIT: well, if you dont mind it a circle, that would make it a whole lot simpler. Just make a circle of r = (x2-x1)/2, and follow the circle arc (on its tangent) until you reach target?
 

Geners

Member
This is exactly what you need, it's just that you wont be able to solve it using y = 0, you will have to plug in your specific points if they are on different heights.
Think of it this way: you have starting point, end point, "gate-point#1" and "gate-point#2". You have all you need to find "a" and "b" from those x's and y's.
There would be 2 solutions, but one will be shaped like a "u", which I assume is not what you want.
But yeah, it's more of a hassle the way you're setup than solving for the same crossing point (tho it's a matter of sitting on it for half and hour, to DIY, really).
You may check GMLscripts.com, maybe there's already something that does just this on there (not sure, but doesn't hurt to look)

EDIT: well, if you dont mind it a circle, that would make it a whole lot simpler. Just make a circle of r = (x2-x1)/2, and follow the circle arc (on its tangent) until you reach target?
Your circle solution is what I was thinking too. I will try that but I'm afraid its path will look too uniform and also I still wouldn't be able to set the height as two points on a circle will always have the same radius.
 
Your circle solution is what I was thinking too. I will try that but I'm afraid its path will look too uniform and also I still wouldn't be able to set the height as two points on a circle will always have the same radius.
Maybe trying to solve the quadratic STARTING with the vertex would be simpler, if it's to be the maximum absolute height, and not a minimum height level, that you want to plug in.
Consider the quadratic written like that y = a(x-b)2 + c
The highest point is going to be (b, c). You plug "b" as "x2-x1", and I think it's smooth sailing from there...maybe? 😂
(Google it just in case, Not 10000% sure, but pretty sure it's something like that)
 

Geners

Member
Also
Maybe trying to solve the quadratic STARTING with the vertex would be simpler, if it's to be the maximum absolute height, and not a minimum height level, that you want to plug in.
Consider the quadratic written like that y = a(x-b)2 + c
The highest point is going to be (b, c). You plug "b" as "x2-x1", and I think it's smooth sailing from there...maybe? 😂
(Google it just in case, Not 10000% sure, but pretty sure it's something like that)
I think this would find for me a parabola with the correct vertex (in between the two points) but would this guarantee that this line would pass through both the beginning point and destination point?
 
Yep. The endgame is you gotta write a script that will need to solve "a".
So far, we have "b" and "c", represented by summit vertex.
Then, you use obj_1 position and obj_2 positions (their y will be different, that's why you gotta plug both) to solve the quadratic equation. Both would have a common solution.
Pretty dull, huh?
EDIT: Thinking about it, just plugging obj_1 will be enough! A starting point and a summit has only one possible equation.
 

Geners

Member
Yep. The endgame is you gotta write a script that will need to solve "a".
So far, we have "b" and "c", represented by summit vertex.
Then, you use obj_1 position and obj_2 positions (their y will be different, that's why you gotta plug both) to solve the quadratic equation. Both would have a common solution.
Pretty dull, huh?
EDIT: Thinking about it, just plugging obj_1 will be enough! A starting point and a summit has only one possible equation.
Will just the vertex be enough information that it will always path through both points? Actually, you know what? I think vertex form was what I was looking for after all, which makes me feel like a complete idiot. I'm going to plug it in and make sure we were right, but regardless of the outcome thanks for the help.
 
With just a vertex and a starting position, you wont be able to "aim" at a target, you have to compute the "b" (x of vertex) with both the shooter and the target position (assuming the summit is in the middle, which would look the best, imo), and plug in manually the desired height ("c", or the y of vertex).
Don't feel like an idiot, mate, I'm betting 98% of your friends can't divide 7 by 3! (Mine dont, in any case! 😂 )
 

Geners

Member
With just a vertex and a starting position, you wont be able to "aim" at a target, you have to compute the "b" (x of vertex) with both the shooter and the target position (assuming the summit is in the middle, which would look the best, imo), and plug in manually the desired height ("c", or the y of vertex).
Don't feel like an idiot, mate, I'm betting 98% of your friends can't divide 7 by 3! (Mine dont, in any case! 😂 )
Okay this more or less works but now I'm having trouble figuring out what the "a" point should be. Is there a way to figure this out without the knowledge of what y is going to be at any given point?
 
Finding the a is the end goal, theres no way you can even know the y position on any x without it
y = ax2 + bx + c
You have x and y (starting position)
You have b and c (b being the middle point between shooter and target, and "c" being max height (maybe set by a "power" variable, or something))
So, if we do some algebra:
a = ((y - c - bx)/x2)

Only by solving "a" will you be able to get all y positions on any point between shooter and target

Should be something like that...
 

Geners

Member
Finding the a is the end goal, theres no way you can even know the y position on any x without it
y = ax2 + bx + c
You have x and y (starting position)
You have b and c (b being the middle point between shooter and target, and "c" being max height (maybe set by a "power" variable, or something))
So, if we do some algebra:
a = ((y - c - bx)/x2)

Only by solving "a" will you be able to get all y positions on any point between shooter and target

Should be something like that...
Would I just use my starting y coordinate for the y on the right side of the equation?
 

Geners

Member
Maybe trying to solve the quadratic STARTING with the vertex would be simpler, if it's to be the maximum absolute height, and not a minimum height level, that you want to plug in.
Consider the quadratic written like that y = a(x-b)2 + c
The highest point is going to be (b, c). You plug "b" as "x2-x1", and I think it's smooth sailing from there...maybe? 😂
(Google it just in case, Not 10000% sure, but pretty sure it's something like that)
Okay so I did my own rearrange of the formula and I got
a = y-c/(x-b)^2
Which works.... PERFECTLY

Thanks so much!
 
It should, tho. If you have your a, your vertex point and your target's x position, it should be as simple as plugging it all in the basic quadratic formula, which will return your target's y. Doesn't matter if it's not at the same height as the starting point at all. The way we solve this kind of all depends on what are the unknown parameters at the beginning.
 

Geners

Member
It should, tho. If you have your a, your vertex point and your target's x position, it should be as simple as plugging it all in the basic quadratic formula, which will return your target's y. Doesn't matter if it's not at the same height as the starting point at all. The way we solve this kind of all depends on what are the unknown parameters at the beginning.
I can make it START or END from any given position. But I can't make it start from a given position and go through a given position at varying heights.


here's the create event
Code:
image_index = 1;
pud = instance_nearest(x,y,o_pud);
elstep = 0;
image_speed = 0;
beginX = x;

b = ((beginX + pud.x) * 0.5);
height = -200;
c = height + pud.y;
a = ((pud.y - c)/power((pud.x-b),2));
Here's the step event
Code:
elstep++;

x = lerp(x,pud.x,elstep/480);

y = a * power(x - b, 2) + c;

This is because We've set the vertex in the middle of the two points, so they must always be symmetrical to each other.
 
Last edited:
I understand the issue. This is more complicated..."b" wont be equal to x2-x1, so we have to find another way to find "b", based on 2 known points along the curve...
(Believe it or not, I kind of like these sorts of problems)
I'm starting to think a simple tween could solve this in a line or two, but I had a long day and need a blunt and a game of XCOM to clear my head, at this point!
Let me do some thinking, sleep on it, and I'll get back to you tomorrow, mate!
 
I got it, man. This was really messing with my head, lol. 😂
Turns out if you change the relative height of target and shooter, the "summit" really is not the summit anymore.
Its a 3 equations / 3 unknowns thing.
But this will ensure you always pass through your vertex point, tho...might be a mess to implement with moving targets, this will not adjust for target speed (a little above my paygrade, I think...maybe not...)
 

Geners

Member
I got it, man. This was really messing with my head, lol. 😂
Turns out if you change the relative height of target and shooter, the "summit" really is not the summit anymore.
Its a 3 equations / 3 unknowns thing.
But this will ensure you always pass through your vertex point, tho...might be a mess to implement with moving targets, this will not adjust for target speed (a little above my paygrade, I think...maybe not...)
That should be perfect! I don't need a certain speed, I just need the object to get to the locations in a certain time frame which I'm accomplishing with a lerp of X.
If you have time could you explain this math to me? If not that's fine, but I don't quite understand the code.
 
Simple principle, but lots of algebra:
We have 3 equations:
Code:
y1 = ax1^2 + bx1 + c
y3 = ax2^2 + bx2 + c
y3 = ax3^2 + bx3 + c
1- Use the first one, isolate "a", as in a = THAT_THING
2- Plug THAT_THING in place of "a" in the second equation
3- Use that second equation, isolate "b", plug it in the third equations
4 - Use the same principle in the 3rd equation to isolate "c".
(Probably not the best way to explain in words how to solve a 3-unknowns/3-equations problem, but I'm sure Youtube or Google can come up with the textbook-definition for it! Still working on my teaching skills, lol)

Once you plug it all in and simplify, the "a", "b", and "c" results are what you can see in the beginning of the video, which is
GML:
a = (((x1*(y3-y2)) + (x2*(y1-y3)) + (x3*(y2-y1)))  /  ((x1-x2)*(x1-x3)*(x2-x3)));
b = (((y2-y1)/(x2-x1)) - (a*(x1+x2)));
c = y1 - (a*power(x1, 2)) - (b*x1);
This doesnt use sprites at all, so you can just run and play to check it.
Dropbox link
 

Geners

Member
Simple principle, but lots of algebra:
We have 3 equations:
Code:
y1 = ax1^2 + bx1 + c
y3 = ax2^2 + bx2 + c
y3 = ax3^2 + bx3 + c
1- Use the first one, isolate "a", as in a = THAT_THING
2- Plug THAT_THING in place of "a" in the second equation
3- Use that second equation, isolate "b", plug it in the third equations
4 - Use the same principle in the 3rd equation to isolate "c".
(Probably not the best way to explain in words how to solve a 3-unknowns/3-equations problem, but I'm sure Youtube or Google can come up with the textbook-definition for it! Still working on my teaching skills, lol)

Once you plug it all in and simplify, the "a", "b", and "c" results are what you can see in the beginning of the video, which is
GML:
a = (((x1*(y3-y2)) + (x2*(y1-y3)) + (x3*(y2-y1)))  /  ((x1-x2)*(x1-x3)*(x2-x3)));
b = (((y2-y1)/(x2-x1)) - (a*(x1+x2)));
c = y1 - (a*power(x1, 2)) - (b*x1);
This doesnt use sprites at all, so you can just run and play to check it.
Dropbox link
After some research on finding a quadratic function using 3 points, I understand how you got to this formula. This is really excellent information to have. Thank you SOO much dude for sticking it out with me.
 
After some research on finding a quadratic function using 3 points, I understand how you got to this formula. This is really excellent information to have. Thank you SOO much dude for sticking it out with me.
No problem, mate, I wouldn't do game dev if I didn't loved problem solving! This was fun! :)
 
Top