8
\$\begingroup\$

There are a lot of PC car racing games around which have this unique driving assist which helps brake your car so that you can safely turn it. While in some games it just an 'assist', it will just help your car brake but won't ensure a safe turn. While in others, the braking assist will help you get a safe turn. I was wondering on what could be the algorithm that is followed to achieve it.

A very basic algorithm I could think of was,

  • Pre-determine the braking distance of an ideal car for every turn of the track, depending on the radius of the turn, and then start braking the car accordingly. For example, for a turn of less than 90o, the car would start braking automatically at 50m distance from the start of the turn.

A more advanced algorithm, which would ensure a safe turn, could be

  1. Pre-determine the speed of the car at the start of each turn, individually for each track, turn and car. Also, pre-determine the deceleration rate of each car individually, which varies because of the car's performance.
  2. The braking assist would keep recording the speed of the car at a certain instant of time.
  3. Start braking the car appropriately so that the car gets to the exact speed needed at the start of the turn.
  4. For example, let the speed of a particular car at the start of a turn 43m in radius, be 120km/h. Let the deceleration rate of the car be 200km/h2. If, at some instant of time, the speed of the car is 200km/h, then the car would automatically start braking at 400m from the start of the turn.
\$\endgroup\$
4
  • 2
    \$\begingroup\$ More sophisticated options would factor in the weather, road surface, weight distribution of the car, characteristics of the suspension and tires. I've seen games like Real Racing 2 where upgrade options modify suspension and tyres and some others allow suspension tuning. A game with persistent world characteristics could take into account accumulated crap on the road and changing wear and stiffness of tires as they warm up. \$\endgroup\$
    – Andy Dent
    Commented Dec 20, 2012 at 6:28
  • \$\begingroup\$ [it seems I cant comment yet, so I post this as an answer] In addition to the second of Your proposals I would tweak this algorithm to brake slightly too much so that the speed at the beginning of the turn is lower than the optimal speed. The intention here is that player should discover that he can take the turn faster without going out of track if he don't use the assist. I'd like to encourage player to disable assists which should make him more proud of himself. \$\endgroup\$ Commented Dec 20, 2012 at 9:58
  • \$\begingroup\$ Would any algorithm here be noticeably different than controlling an AI opponent? \$\endgroup\$
    – tugs
    Commented Dec 20, 2012 at 18:10
  • \$\begingroup\$ Not noticeably, but yes, different in many aspects. You can make AI move at any speeds and angle and still make a normalized movement impression. In this case, an AI character can turn even at the speeds of 160km/h, even if its not possible, but the first algorithm here wouldn't allow a player to do that. Even for the second one, the role of the assist is to get the car to the optimum speed required at the start of the turn. If a player plans on increasing his speed thereafter, he won't be able to turn. \$\endgroup\$ Commented Dec 22, 2012 at 9:37

2 Answers 2

4
\$\begingroup\$

Fundamentally, braking assist works comparing the player's car's speed against the speed of the nearest point on the track's optimal racing line, and automatically applying the brakes as needed to bring the player's car's velocity down to match the speed specified on the optimal racing line. It's exactly like writing racing car AI, but only applying the AI's brake outputs, not the accelerator or steering.

This does (obviously) require you to have data about an optimal racing line, so you can tell how much the player needs to slow down. This racing line is typically generated computationally during development, and is shipped with the game as a piece of static data, rather than being calculated at run-time. (I have worked on games which dynamically generated a racing line in front of the player, but this was computationally expensive, and I don't recommend it unless you have tracks that change in unpredictable ways)

\$\endgroup\$
1
\$\begingroup\$

You could calculate the path the car would describe if it turns with the current speed without drifting. Then apply brakes in proportion to the distant d, which is the distance measured from the calculated path to the curve.

enter image description here

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .