determining the starting speed for an accelerated animation (in flash/actionscript but it's a math question)
Posted
by
vulkanino
on Stack Overflow
See other posts from Stack Overflow
or by vulkanino
Published on 2011-01-07T08:34:50Z
Indexed on
2011/01/07
12:53 UTC
Read the original article
Hit count: 142
This question burns my brain.
I have an object on a plane, but for the sake of simplicity let's work just on a single dimension, thus the object has a starting position xs. I know the ending position xe. The object has to move from starting to ending position with an accelerated (acceleration=a) movement. I know the velocity the object has to have at the ending position (=ve). In my special case the ending speed is zero, but of course I need a general formula. The only unknown is the starting velocity vs.
The objects starts with vs in xs and ends with ve in xe, moving along a space x with an acceleration a in a time t.
Since I'm working with flash, space is expressed in pixels, time is expressed in frames (but you can reason in terms of seconds, it's easy to convert knowing the frames-per-second).
In the animation loop (think onEnterFrame) I compute the new velocity and the new position with (a=0.4 for example):
vx *= a (same for vy)
x += vx (same for y)
I want the entire animation to last, say, 2 seconds, which at 30 fps is 60 frames. Now you know that in 60 frames my object has to move from xs to xe with a constant deceleration so that the ending speed is 0. How do I compute the starting speed vs?
Maybe there's a simpler way to do this in Flash, but I am now interested in the math/physics behind this.
© Stack Overflow or respective owner