Race against the computer drivers in this all-action speed game! Use the cursor keys to steer your cart around the airport, avoiding crashing into things!
There are three tracks of varying difficulty to race on, and practice/race modes to try out.
Postmortem:
I’ve always loved cars, driving and everything associated, including racing games. I was thrilled to be building a driving game to promote a film, even if the film was one of those Christmas cash-in kids flicks that hardly anyone had heard of (I haven’t even seen it myself, several years later).
Having never built a driving game before, I had a lot of technical issues to solve in a relatively short project build time. Given that the cars in question were airport baggage handlers, I thought it perfectly acceptable to cheat and give them perfectly sticky tyres, which made dealing with things like realistic skids, oversteer, understeer, handbrake turns etc much easier: They simply didn’t exist in this game.
Surprisingly, this technique worked just fine and the game feels perfectly OK. There’s an issue with not being able to see far ahead on the track (partly solved by scrolling the player’s car to the opposite side of the screen to the direction of travel).
To give the illusion of sliding, I added faux skidmarks that fade in whenever the player has been accelerating and turning for more than a set amount of time, and also when they brake. This turns out to be easily sufficient for an arcade racer like this! It’s surprising what shortcuts you can get away with sometimes. Skidmarks are attached permanantly to the track, which is bad for performance but looks great after a few laps.
Graphically, it’s pretty easy to get lost on-track sometimes. You kind of have to learn which way to go on a slow lap, then put your foot down later. I suppose that’s what the practice mode is for, but I can’t help but think it would have put some players off to be constantly crashing into the walls.
On the subject of crashing, the collision detection and response was another technical issue. Car to car collisions were done by detecting when two cars were within a certain distance of each other and tweaking their position apart like billiard balls, then applying a small speed penalty. This works remarkably well, and gentle nudges don’t penalise you much so you can go for those risky overtake opportunities without fear of ending up miles behind. It helps the AI to stay on course too.
Collisions between the cars and the track edges however are not so good. I built several test concepts, none of which really worked before settling on one that was more or less adequate. It still isn’t good though, and really could have done with lots more work if the project were given extra time. The way it works is to test the corners of the player’s kart against a giant hit shape that covers the track. If a corner is in collision, a circle of samples is taken around that point. An approximate line is generated here, and the player’s car is pointed along the reflection vector of this line. The problem however is that the line approximation is a bit flaky, and varies considerably depending on exactly where the samples fall. This means you can be turned unfairly into the wall rather than away from it, or bounced inside the collision shape and all sorts of other horrible artefacts.
One aspect of this game I’m quite proud of is that the AI players are driving cars that are identical to yours. I.e. each AI player has a virtual left, right, up and down control that they can press. The rest of the sim of the car is identical to the human’s car. Except it isn’t collided with the scenery! The AI isn’t smart enough to get out of a bad collision with the edge of the track, and at the time most people’s computers weren’t really fast enough to run the collision detection for all 6 cars together either. The AI follows a virtual track path that differs for their ability. A good AI driver follows a neat track path. A bad AI driver follows a wonky path that misses apexes etc. The path doesn’t define exactly where to drive, but defines a line to be followed if possible. The computer measures its distance from the path and steers towards it appropriately, following an algorithm that real industrial robots use to navigate warehouses. This means it can deal with moderate perturbations from the given path if the player collides with it and pushes it off course.
The game was well received by people who played it, it seems. This may be to do with the fact that most Flash racing games are total junk! In fact, I don’t think I’ve played one yet that I really like a lot, including my own!
Lessons:
- Racing games are popular!
- Racing games are tricky to write and balance
- AI drivers are hard to program!
- If you spend the time to make a good driving game, spend a bit longer filling it with plenty of tracks too. Three isn’t enough.
- If you add a bit of code that doesn’t work very well, don’t just accept it! Find a way to make it better or suffer the consequences