Create a Flash Racing Game Tutorial – Artificial stupidity

I promised I’d introduced artificial intelligence in a racing game, and I am starting with artificial stupidity.

Anyway, I managed the car to somehow run around the track. I said “stupidity” but I should have said “blindness”, because the CPU driver is actually blind.

How would you react if you were blind and crazy enough to try to run around a track with the pedal to the metal?

I would run as fast as I can until I realize I am out of the track. Then I would decelerate until I realize whether I am out on the left or on the right side of the track, and keep on steering until I am on the track again.

This is what happens if you change car_mc class you can find in this example with this one:

As you can see, car completes the track but performances are affected by the blindness of the driver who tries to adjust the vehicle only when he hits something.

Next time, I’ll show you how to make the CPU see the track. No need to download anything, just replace car_mc content with the one on this post.

  • You should rather try attempt with double linked list of waypoints. When car approches to one it starts to follow next and so on.
    You can also implement reducing speed on hairpin bends by comparing current car’s angle and angle to next (or event waypoint.

    Here’s how I got this working:

    Cars do not collide with each other due to short deadline – it would complicate AI, so I had to drop it :(

    Good luck :)

    • Emanuele Feronato

      using waypoints means YOU will decide where cars have to go.

      using the line of sight means CARS will decide where to go… I’ll try the harder approach, anyway thanx for the tip :)

      • Harder doesn’t always mean it’s better. Good luck then, I’ll follow your struggle ;)

    • Thomas

      I made a racing game last year with the waypoints idea, along with some nice radial collisions. Alas, I hadn’t thought of making the cars slow near sharper corners – though, you’d crop up issues when the car’s rotation is 5 degrees and the next waypoint is at 355 degrees.
      I was also never managed to make the cars drive properly straight, but the game was still successful, so no biggie.

  • loop

    Im pretty curious on how you plan to avoid this: the car that decide where to go going the wrong way; without the use of waypoints, or something similar.

  • MC

    i think this can be improved if you check collision BEFORE it happens… then you can prevent collisions instead of react to collisions

  • Quintus Kilsdonk

    how about a slope detection tutorial

  • Me

    Looks like my grandma’s driving ;p

  • Pingback: Create a Flash racing game tutorial – Artificial intelligence - Emanuele Feronato()

  • tom

    I like your car game and I need you to make me some games.

    Example: Horse Racing, Blackjack, Jacks or Better, Hi Lo and more. If you are interested please e-mail with phone number.
    Thank you,

  • I made a game using a mixture of AI and waypoints. The boats would try and work it out for themselves, and if they got lost or predicted they’d be returning to the same spot, resprted to a loose waypoint system. If, however, this failed (and by the final version it very very rarely did) it would warp them back to the last checkpoint (which were far more frequent than waypoints, but only when the boat was offscreen and hopelessly stuck.) It was also my first major dive into the 3D API in Flash player 10, hope you enjoy it :)

  • gino80

    Great stuff Emanuele as usual!!

    it’s much difficult to implement a sort of GHOST CAR?

    I mean a sort of movements recording of the precedent race so after you have to challenge the ghost?

    sorry fo rmy english, hope the concept is clear :D

    thank you veeery much emnauele!!!
    keep your great work!

  • nice racing stuff

  • Monuta forelli

    i have created the Artifcial stupidity by only remove:

    Key.isDown(Key.UP) &&


    if (Key.isDown(Key.UP) && this[“speed”+who <_root.maxSpeed) {
    //if the acceleration key is down, the engine sound volume is set to 100
    this["speed"+who] += _root.acceleration;

    lol this is much easyer and faster to make.

    Monuta Forelli

  • James

    I will be creating a race game almost same as this but race track will be angled… Full race track will be displayed but with an effect of far and near so car must be a little small when far and also some 3d effect when turning… Anyone did this? Thanks!

  • Oskil

    heloo,,can you help me?
    i need tutorial like this game
    help :'(