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 point on the right:
P | 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 (or magnitude/angle) when the player hits the ball so that the ball, affected only by gravity, follows that parabola. Alternatively, the flight time from which the X/Y component velocities can be calculated.
Essentially, what I have is:
- The ball's trajectory (as a parabolic function)
- Acceleration due to gravity
What I need is either:
- Initial compound velocities or magnitude/angle
- Possibly just the flight time? If I divide the distance traveled by the number of airborne frames I can find the Y for any X and just draw the ball where it needs to be.
EDIT: Simplified the description to remove confusion
EDIT: Ok, at the moment I've got a formula for a parabola that goes through all the points I need it to, and I can watch the ball fly through the air by incrementing/decrementing it's X coordinate by a discrete value over a discrete time (say, 60 pixels per second (1px per frame as 60 fps) apologies for the game language). But having a constant horizontal velocity for all trajectories is wrong - I need a constant vertical acceleration (i.e. gravity) for all trajectories and variable horizontal velocity depending on how long/short the range is. It seems like simple Newtonian physics from here so I'll figure it out soon enough.