A Flash Developer Resource Site

1. ## Trajectory Prediction

Have been playing the excellent Sling game here:

http://www.ezone.com/games/sling/gamecode.htm

Does anybody have any advice regarding trajectory prediction, and knowing where a launched object will travel and eventually land?

Is a simulation run in accelerated time, and positions recorded that the object will be at, or is it done some other way?

Any tips would be much appreciated.

2. What you're talking about is "continuous" versus "discrete" physics simulation.

Until you start dealing with collisions, continuous simulation is actually quite easy. The arcs you see in Sling are parabolas; if you throw something in a vacuum, it makes that shape every time. So given a starting position and velocity, you can draw the whole trajectory -- no timestep needed.

This section on wikipedia is pretty good http://en.wikipedia.org/wiki/Traject...o_drag_or_wind

Hitting walls is where it starts to get messy. Really messy. (Take the intersections between the parabola and all the walls. Now that you have the intersections, which one happens first in time?) They probably just used a fast discrete simulation; that's what I would do.

-Neal

3. i think the continuous approach is easier. because the parabola defined by the kinematic equations of motion is a function of time, solving for the point of collision is the same as solving for when it happens. solve for all intersections over your timestep, then move to the "soonest" one. resolve the collision, subdivide the interval into dt - toc, where dt is your timestep and toc is the time of collision you just resolved. repeat until you've integrated over the entire timestep.

4. ## use trajectory of projectile formulae

You can also calculate the final distance, maximum height and time of flight using the formulae from Wikipedia - Trajectory of projectile. Put them as functions in actionscript and calculate the final results.

Continuous animation can be achieved by setting a xVelocity and a yVelocity. The vVelocity is constantly decreased because of gravity. The position of the object will increase with the xVelocity and the yVelocity.

You can also achieve the animation by calculating the time passed and multiply it by the horizontal component of the initial launch velocity, then use the result and put it into "Height at x distance" formulae at around the middle of the wiki page.

Hope it helps!

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 » Home » Movies » Tutorials » Submissions » Board » Links » Reviews » Feedback » Gallery » Fonts » The Lounge » Sound Loops » Sound FX » About FK » Sitemap