Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.
share|improve this question

migrated from superuser.com Dec 20 '12 at 6:36

This question came from our site for computer enthusiasts and power users.

2  
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. –  Andy Dent Dec 20 '12 at 6:28
    
[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. –  Grzegorz Sławecki Dec 20 '12 at 9:58
    
Would any algorithm here be noticeably different than controlling an AI opponent? –  tugs Dec 20 '12 at 18:10
    
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. –  Ayush Khemka Dec 22 '12 at 9:37
add comment

2 Answers

up vote 4 down vote accepted

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)

share|improve this answer
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.