Flash Physics Study | 1 2 3 4 | continued:

 

So, let's tackle this problem. In a normal iteration of time (when the ball is not hitting the ground, or walls, or ceiling), a ball's velocity and position will change in the following way:

 

// Initial velocity changes at any given time
velocityY = velocityY + Gravity * time;
velocityX = velocityX;
velocityZ = velocityZ;

// New x,y positions after this iteration
positionY = oldPositionY + (velocityY * time);
positionX = oldPositionX + (velocityX * time);
positionZ = oldPositionZ + (velocityZ * time);

 


The positions in each coordinate is affected in the same way. The new position will always be the old position plus the change in position (i.e. the velocity of the ball in the given direction multiplied by the time frame of the iteration). For simplicity, we're going to set time = 1, but we leave the variable in here so that the equation makes more sense and it doesn't look like we are adding a position with a velocity.

The velocities are simple for the x and z direction. They don't change. In the y-direction, we need to account for gravity. Remember from the high school physics class you slept through, gravity is an acceleration force. Just as velocity represents the change in distance over time, acceleration represents the change in velocity over time. So, the equation for y-velocity is errily similar to the equations for distance, since it changes over time.

As for the Gravity constant, in high school physics, you learned that the gravity of the earth is typically measured at 9.8 m/s2. That's great and all, but for our Flash purposes, since we are using pixels as our unit of measurement and frame rate as our unit of time, 9.8 really isn't a valid representation. We're just going to leave gravity as a variable that we can change. By letting us vary it, it makes for some nice effects (lowering the gravity to 0 lets the balls "float" in air).

Also, you might be wondering whether our gravitational constant should be negative or positive. Well, because the 0 y-coordinate is defined at the top of the movie, and "positive" values of y actually fall below the 0 line, we want to define gravity as a positive constant so that its force causes the ball to fall.

Now, we're almost there. We've accounted for the velocity and position changes of the ball under normal conditions. Now, we need to implement a series of boundary cases.

 




No Screenshots Available
 

1 | 2 | 3 | 4 | Next

   
Main | Tutorials | BestFlash | Goodies | Forums | Portfolio | Contact Us
   
 
AEvision Tutorials 2.1 - All rights reserved AEvision Designs 2002-2007
 
 
Icons provided by iconpacks.com