You’ll want to set CurveSize0 and CurveSize1 to the same number, except their signs flipped. So for example, CurveSize0 = 10 and CurveSize1 = -10 (or the other way around, depending on your attachment setup).
We can now use some background knowledge about Beziér curves to find out the top height of the curve. Suppose the first attachment is at height Y0, and the second attachment is at height Y1. The top of the curve will be at Y = (Y0 + Y1)/2 + 3/4 * CurveSize. So in the example with the curve sizes above, where the parts are at Y0 = Y1 = 0, the height of the curve would reach up to Y = (0 + 0)/2 + 3/4 * 10 = 7.5 in its centre.
If you want to manipulate the top height of the curve yourself, you can use the following formula to figure out what the curve size should be:
CurveSize = 4/3 * (Y - (Y0 + Y1)/2)
Or just:
CurveSize = 4/3 * Ydiff
(where Ydiff is the amount that the curve should be raised in the middle)
You would then set CurveSize0 to CurveSize, and CurveSize1 to -CurveSize (or the other way around).
Images:
Since curve size is 12 here (+12, -12), the height of the curve is raised 9 in the middle
Hmm… It hits right at the top, but at the other points, especially in the beginning, its not very accurate.
I think it’s because the direction it’s being tossed at isnt straight up…
I don’t think a projectile necessarily follows a bezier path. If you’re simply launching the part using the physics engine, you’re gonna have to do some ballistic projectile calculations first, and then set the beam points and curves (control points).
Yes, the path is calculated already. The issue is shaping a beizer curve that fits the resulting projectiles path.
Lets assume both points have same height to begin with.
If I set the attachments rotation same as the launch angle, what would be the top height of the curve?
If you want this to work and be accurate, you have some algebra to do. Assuming this projectile is being launched and subject only to gravity (not wind resistance), what you probably want is for the beam to show the path of the centroid of the thing being thrown, which is a parabola. Beams use a cubic Bézier curve, which can fit any parabola section exactly, so that’s not a problem. The simplest thing to do is to express the path of your object first as a position function of time, normalized for t=[0,1]. You can then set that parametric parabola equal to the cubic Bézier equation (see wikipedia page for Bézier curve), and solve for the two unknown control points (the scalar distances from the endpoints, CurveSize0 and CurveSize1) in terms of your known control points (the path endpoints) and the launch velocity.
Your launch angle is presumably known, and your landing angle is easily gotten from the derivative of the parabola at t=1. Even though you’re probably launching things in many different directions, you should solve this as a 2D problem.
Hmm… Would you know how to get the maximum-Y value of a beizer curve?
More specifically, where both controlpoints are at same position, forming a parabola.
Dude I want to take pathfinding and turn it into a beam path with an arrow at the end, it may involve using what is involved in this to get those curves.
Yeah, you just solve for where the first derivative of the curve is 0 (specifically the Y component if you’re doing it all with 2D vectors). The wiki page already has the derivatives shown too.