PDA

View Full Version : Accelaration physics in ActionScript (Flash MX Game Design Demystified)



Kostanzas200
January 2nd, 2008, 08:34 PM
Hi forum,
I am having problems understand the formula of finding the future x and y position of an object in regards to accelaration.

I have encountered this problem in the book Flash MX Game Design Demystified.
The problem I am having is in regards to a section on Accelaration. I will point out the explanation given in the book and what I do not understand, ok, here it goes: (the following is an excerpt from the book)

[Book excerpt]
If you know the current position and velocity of an object, then you can find its position at any time in the future. You can fidn the future position by using the following equation:
xposition_future = xposition_now + xspeed_now*time + 1/2*(xaccelaration)*time^2
and
yposition_future = yposition_now + yspeed_now*time + 1/2*(yaccelaration)*time^2
[/Book excerpt]

While I understand the first part of both equations, that is, taking the current x position of an object and adding the speed times time of that object. So if you had a dot at (5, 0) and it was moving at 3 points per frame (using Flash frames as the measurement of time), then the future position of it in say 5 frames would be 5 + 3*5 = 20. This part I understand.

However the second part of the equation, which states '1/2*(yaccelaration)*time^2'. I do not have a grasp on.

I would greatly appreciate help from anyone who can explain this formula with a practical example.

Thank you for your help in advance
Kosta

Dhryn
January 3rd, 2008, 12:46 AM
It is taken from the physics equation s = ut + 0.5*a*t^2, also written as r = ut + 0.5*a*t^2 in mechanics.

s / r = Displacement / position
u = initial velocity
v = final velocity
a = acceleration
t = time

The second half of the equation (0.5*a*t^2) is taking acceleration and converting it into a position using time. As the acceleration is constant you can times by time and get the velocity, the equation so far would be a*t

example:
A stone is dropped from rest, what is its velocity after 1 second (t = 1), acceleration is 9.81 (gravity) so the velocity is 9.81 * 1, after 2 seconds 9.81*2 and so on.

example 2:
A sprinter sets off from rest with a constant acceleration of value 2 (a = 2), what is the sprinters velocity after 4 seconds (t = 4), 2*4 = 8 therefore the velocity is 8.

To convert velocity to position you have to consider the fact that the velocity is constantly changing at a uniform rate, on a graph this would be a straight line that would be neither vertical or horizontal, this therefore forms a triangle on the graph. the position is the area of the triangle on the graph, to work out the area of a triangle you use the equation -

0.5*height * length

this comes out as 0.5*velocity*time (0.5*v*t), we found velocity earlier that was v = a*t, substituting this in you get 0.5*a*t*t or 0.5*a*t^2

example:
the stone is dropped, its has an acceleration of 9.81 (gravity) (a=9.81), how far has the stone dropped after 4 seconds (t = 4). 0.5*9.81*4^2 gives the final velocity after 4 seconds

example 2:
A sprinter sets off from rest, with a constant acceleration of 2 (a = 2), how far has the sprinter run after 3 seconds (t = 3). 0.5*2*3^2 gives the final distance the sprinter has run after 3 seconds.


Looking at acceleration/time graphs, velocity/time graphs and displacement/time graphs might also help with this.

I hope this helps

Kostanzas200
January 3rd, 2008, 03:37 AM
Thank you Dhryn, that was the best explanation I could have asked for and I completely understand it.

I hope to be able to ask you more questions as I go through the book and I would much appreciate any more help you could give me.

Regards
Kosta