A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Trajectory Prediction

  1. #1
    Junior Member
    Join Date
    Aug 2007

    Question Trajectory Prediction

    Have been playing the excellent Sling game here:


    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. #2
    Bacon-wrapped closures Nialsh's Avatar
    Join Date
    Dec 2003
    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.

    Last edited by Nialsh; 11-25-2010 at 08:39 PM.

  3. #3
    Senior Member
    Join Date
    May 2006
    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. #4
    Senior Member
    Join Date
    Dec 2010

    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

Click Here to Expand Forum to Full Width

HTML5 Development Center