Skip to main content
Search IntMath

Math in computer games

By Murray Bourne, 30 Jun 2007 has an excellent tutorial which explains how to get realistic effects in Flash-based games. And of course, you need some mathematics to achieve that.

A tutorial on developing a car racing game in Flash involved the following mathematics (the links go to explanations of the math):

  • Acceleration (and deceleration, which they call "speedDecay") and velocity
  • Trigonometry (including sine and cosine of angles)
  • Conversion of degrees to radians (Flash uses an odd mix of degrees and radians): angle_radians = angle_degrees * (PI/180)
  • Cartesian coordinate system
  • Collision detection (and behaviour after a collision) involves detection of the car's position, angle and speed
  • The floor and rounding functions:
    seconds = Math.floor(milliseconds/1000); [this means round the number down to the next lowest whole number], and
    tensTXT = Math.round((milliseconds-seconds*1000)/10); [this is normal rounding]
  • And of course, they are using addition, subtraction, multiplication and division - which is really all we are doing for most of the time in mathematics

The explanation for realistic steering gives an insight into how they use math to get the desired effect:

We could simply add or subtract a fixed angle (in degrees) to/from the car's rotation, but that's not good enough. In order to simulate a natural movement, steering must depend on speed, otherwise you will be able to rotate your car even if it's almost stopped and it will look like a propeller 🙂

One day I hope to get time to write some tutorials on the maths behind the math applets and activities on Interactive Mathematics that I wrote.

See the 2 Comments below.

Leave a comment

Comment Preview

HTML: You can use simple tags like <b>, <a href="...">, etc.

To enter math, you can can either:

  1. Use simple calculator-like input in the following format (surround your math in backticks, or qq on tablet or phone):
    `a^2 = sqrt(b^2 + c^2)`
    (See more on ASCIIMath syntax); or
  2. Use simple LaTeX in the following format. Surround your math with \( and \).
    \( \int g dx = \sqrt{\frac{a}{b}} \)
    (This is standard simple LaTeX.)

NOTE: You can mix both types of math entry in your comment.


Tips, tricks, lessons, and tutoring to help reduce test anxiety and move to the top of the class.