views:

72

answers:

4

For example in Peggle or Apple Jack, the user can move around a curve showing where the ball (or the washing machine / panda or whatever) is about to go before the user has requested that the projectile is launched. I know i need to use an equation to plot the points but I'm no mathematician (anymore :(). Can anybody be so kind as to provide me with the correct equation and tell me what I should substitute in to get my X any Y values given a certain time and initial velocity.

A: 

You could use newton's method of approx. solving. The problem here is that you need to integrate - so you have to define the trade-off between preciseness and calculation time.

RK4 is the method that is best in my opinion - it is fast and still very precise.

You can read more info at http://gafferongames.com/game-physics/integration-basics/

data_smith
+1  A: 

If this is a projectile following a simple ballistic trajectory, you can use the closed-form expressions provided here:

http://en.wikipedia.org/wiki/Trajectory_of_a_projectile

If not, it might be a lot simpler to simulate the effect of all the forces on the body for each (small) time-step, updating its position and velocity accordingly. This technique is more robust; you can add a lot more complexity to the problem without changing the basic methodology.

Ani
+2  A: 

Simulation would probably be the easiest route to go down: create a dummy object with the specified properties and create a loop to apply the forces and say output the positions to an array and then display it, say: draw a line between the positions or draw a "ghost" of the projectile at each position.

A positive thing about simulation is you can control the balance of speed and accuracy by changing how often you record the positions.

Blam
+1  A: 

Take a look at my answer to this question.

Taken from that answer, the formula you should be using is:

s = s₀ + v₀t + ½at²

(Displacement equals: initial displacement, plus initial velocity multiplied by time, plus half acceleration multiplied by time squared.)

Everything except time there is a vector (acceleration will be your downwards gravity). So simply use that equation on both your X and your Y axis.

Of course - the only way to guarantee that the plotted path will match your prediction equation exactly is if they are the same. That is the only way I can see for you to add support for predicting bounces.

If your actual game uses something different (like a full physics simulator), and you don't need to predict bounces, and you don't have to be perfectly accurate - then this will give you a suitable approximation for the prediction.

Andrew Russell