I'm working on a volleyball game but my maths/physics knowledge isn't quite up to par. I need some help with the following problem:
The player can hit the ball from anywhere on the left of the court into one of three points on the right:
P | x x x
The ball travels in a parabola defined by the three points, all of which are known:
- The players X coord and height (Xp, Yp)
- The point just above the top of the net (0, Yn) (assume the left of the court is negative along the x axis)
- The point where the ball impacts the ground on the other side of the net (Xi, 0)
I need to calculate the initial X/Y velocities when the player hits the ball so that the ball, affected only by gravity, follows that parabola. EDIT Alternatively, the velocity magnitude and angle from which the X/Y component velocities can be calculated.
I'm able to find the function of the parabola using pen and paper but since this involves "saving" equations with unknown variables I have no idea how to translate that to code (how could you have variable a = 2b for example if b is undefined?). I'm not even sure if finding the function is necessary for this problem.
EDIT: I just came to the realisation that if I can calculate the flight time then I can divide the distance traveled each frame along the x axis and just plug that into the parabolic function to get the ball's y coordinate. I guess that's my next avenue of research.