开发者

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.


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.


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.


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.


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/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜