6
\$\begingroup\$

For a projectile starting at origin O, an initial velocity V, and several stationary planets P[n], how would I pre-calculate and store the path it would take without actually stepping through each frame along the curve?

Several planets with a red line bending toward each one.

I have some idea of how to do this for a single gravity source (conic section, parametric curves), but how do you blend multiple forces, and thus multiple curves, together?

The idea is to give the player some idea of the trajectory their shot will take, so it doesn't need to reflect the actual path exactly, but the closer the better.

\$\endgroup\$
  • \$\begingroup\$ If you are really dead-set against running the simulation frame-by-frame (even offline), you may want to ask this over on the physics site instead. (If you do, please delete this question or let me know so I can delete it.) \$\endgroup\$ – Josh Dec 13 '13 at 18:00
  • 1
    \$\begingroup\$ A continuous physics equation isn't likely to match very well with the actual discrete frame-by-frame simulation. You're likely much better off faking it by simulating the discrete simulation in advance. \$\endgroup\$ – MichaelHouse Dec 13 '13 at 18:03
  • 1
    \$\begingroup\$ Do any of the other bodies move? If so, welcome to the n body problem. \$\endgroup\$ – DampeS8N Dec 13 '13 at 18:35
  • \$\begingroup\$ They're fixed in place. I'll add some more background to the question. \$\endgroup\$ – jzx Dec 13 '13 at 20:15
5
\$\begingroup\$

You step through the simulation quickly, in a for loop or a while loop depending on what the goal is. You're essentially simulating the frames in the loop with predetermined time steps, ideally with the same value as your fixed time step. Depending on how you have your game set up, this could be as easy as using your existing functions.

\$\endgroup\$
  • \$\begingroup\$ In other words, run the simulation for so many steps, each a certain amount of time apart, interpolating the velocity, and build the curves that way? \$\endgroup\$ – jzx Dec 13 '13 at 20:14
  • 1
    \$\begingroup\$ Exactly. The same way you'd run the simulation if you were doing it frame by frame. Except instead of waiting for a certain amount of time to pass between frames, you're just going to pre-define a delta time for all the frames. Save the position of the object at each iteration of the loop into an array. Draw a line between all those positions to get a line. \$\endgroup\$ – MichaelHouse Dec 13 '13 at 20:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.