Search code examples
c#xnagame-physicsfarseer

Plotting points for a projectile before a force is applied


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.


Solution

  • 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.