Home | AI | Physics | Mathematics | Compiler Design | Games | Downloads | About Me
You are visitor number 147044 since February 2003
Physics
Introduction
Velocity
Acceleration
Momentum
Collisions
Gravity
Friction
 
Free Books


Acceleration

Acceleration is to Velocity what Velocity is to Object position. It is defined as the rate of change of velocity per unit of time. An example of this is when we press the gas pedal down in our car, where the velocity continues to change until it reaches stability.

To model acceleration in a game is as simple as adding a constant value to velocity per unit of time (note that acceleration is also represented by a vector). This is what gives rise to acceleration. This is the same as pressing the gas pedal down in our car. To stop accelerating, we just stop adding this constant value. This is the same as releasing the gas pedal of our car. The math behind acceleration looks like this:

velocity = velocity + acceleration, where velocity and acceleration are vector quantities.

If the formula above is used for every game cycle, and the velocity is used to move an object, this will result in the object moving faster and faster every cycle, because as we know from the velocity tutorial, the object moves according to the velocity. If the velocity is constant, the object moves at the same passe, but if the velocity increases as well, the object will move faster and faster. Here are the formulas for each component of velocity:

velocity_x = velocity_x + acceleration_x
velocity_y = velocity_y + acceleration_y
velocity_z = velocity_z + acceleration_z

In a game loop we would use the formula above first to accelerate our object, and then we would move the object, by adding velocity as follows:

for each cycle
     v = v + a, where v and a are vector quantities representing velocity and acceleration respectively.
     // now we move our object
     p = p + v, this is the formula from the velocity tutorial.

As an example of acceleration, I have created the Flash movie below. You can play around with the car by moving the car forward and backwards, turning left and right. That is, pressing the pedal and releasing the pedal. If you release the accelerator (up for positive acceleration and down for negative acceleration) the car will stop after a while due to friction that I have added to the car. Have a look at the friction tutorial to understand what friction is and how it is modelled in video games.. Play around with it and watch the values of speed (the magnitude of velocity) increasing and decreasing.

Note that in this example, the acceleration is constant. This isn't the case in real life. In real life acceleration increases and decreases according to an external force applied to the body. That is, we use Newton's second law to calculate this. This is the formula:

F = m × a, where F is the force being applied to the body, m is the mass of the body and a is the acceleration caused by the force.

Note that F and a are in boldface, indicating that they are vector quantities. m is a scalar quantity. If you want to find out the acceleration resulting from the force, you just work the form to become this:

a = F ⁄ m

This force may be thurst applied to our car, for example. As the force builds up, our acceleration also builds up. If we use this formula in our game cycle, our velocity will build faster and faster, and so will be the movement of our object. Play around with this values to see how that works out.

If you have any queries regarding this tutorial, please do not hesitate to contact me.

Best Regards

Fidel






Books



© 2002, 2003 Fidel Viegas. All rights reserved.