2 Alex Darby FreeStyleGames Ltd (www.freestylegames.com) Downforce PS2 Moves Track Not Car
3 Track SpaceTrack modeled as long strip with fixed width=1 and an infinite length2 Major pieces of knowledge about carHorizontal position on the track (fWidthPos)Location from some “start” point (fLengthPos)This location is course and track dependentfLengthPos = X.yyX = position on trackYy = %done with the current position
4 Track SpaceFor car not seen:fWidthPos=.75fLengthPos=42.333
5 Downforce AI SystemNote Layers, all take same input
6 Layers in AI Operate in Psudeo-Parallel Behaviors Code executed seriallyCongitative System not used until all layers are done processingBehaviorsEach layer composed of behaviorsBehaviors are independent but operate much the way the overall layers workLayer Interaction – Layers canOverride the results of other layersLayer mode switiching – defesive to aggressive
7 Path Following LayerCorrect controller inputs so a vehicle can follow a specific path at max speed.Two behaviorsSteering ControlCorner Speed RegulationSteering to follow vehicle racing lineSteering to converge back onto racing line if lostSince working from same input data, subtasks can be independentSaves in computational timeLess code
8 Path Following Cont... Corner Speed Regulation Only following race line, cares about nothing else (ie obstacles, track conditions, etc)Dead-Reckoning ApproachFSM based around cornersCorner Identification – including corner apexBraking distance is calculated based on current speedBraking For Corner – break until the current speed is the same as the necessary speed to clear the corners apexCruse To Apex – controls throttle so that it does not go too below corner breaking speed, and then accelerates once the apex of the corner is reached.Corner – a section of track which the vehicle is unable to ravel through at its current speed without losing control
9 Fine Grain Avoidance Layer Deals with potential collisions the other layers have notTwo behaviorsRace PriorityCollision Avoidance (side-to-side)Race Priority selects which AI will back off incase of collisionPlayer has significantly higher priority“Inside” car around a corner gets priority
10 Avoidance Cont… Side-to-Side collisions Front-to-Back collisions Overrides steering/speed from Path Following LayerDependent on Race PriorityIf “outer” car will collide with inner car, limits the speed and steering to run parallel slightly behind the inner carFront-to-Back collisionsRear car must make sure not to hit car in front of it.Override Breaking/Throttle from P.F.L.Avoids collisions that have not been done by the Optimum Road Position LayerSide-to-side: Only does this if does not have race priorityFront-to-Back: only occurs when cars are very close, to encourgae high speed passing/drafting.
11 Tactical Racing LayerAssists in change of speed & racing line in a pack of cars to gain an overall advantageThree behaviorsOptimum Road PositionNew Race LineCollision Avoidance Speed Control
12 Optimum Road PositionEach Car has 4 simple “eyes” to find relative speed of other cars, and their proximityEach eye stores a 1D that represents the entire track width.The 4 eyes give a low resolution image of what is ahead, next to and behind the car
13 Determining Optimal Line 4 “Eye” images combined, current racing line added in.Determine best place to “be” based on the locations of others and racing lineSimple mathematical average of current positionsMust be fine tuned for each track
14 Path GenerationOnce a new position have been identified to give vehicle an “advantage” a new race line must be constructedOld racing line is buffered, and simply interpolated in track space toward the new optimal positionSometimes this new line may go off the track, in which case other layers have to deal with it
15 Collision Avoidance Handles most of front-to-back collisions Only occurs if vehicle in front is currently going slower.Ignores curves in track, simply brakes to avoid a car in front based on current speeds and fWidthPos of both carsNot super efficient, but cheap, reliable and sufficiently accurate
16 Driving Assist LayerControls obscure events such as brake lock, wheel spins and washing outTwo behaviorsTraction ControlAnti-Lock BrakingTraction Control minimizes slippageOnce the slip in the lengthwise axis > threshold value, actual slip is calculated
17 Slip Cont…Also a min throttle value to start slipping to force high power-weight cars wouldn’t slip a greater amount then expected when at a standstill.Type of car (4wd, fwd, rwd) must be taken into account, as to which wheels to measure slip from and how to determine curvature of car from slippage. (direction of the skid)
18 Anti-Lock BreakingSame Code as Traction Control System, but by scaling brake value under breaking, instead of throttle under accelerationIn straight line, forces wheels to lock up, but breaking efficiency is less then with a drum break wheel lockup. This is not how the real world works, but was deemed acceptable in the game.
20 AI System Wrap Up Modular Independent Scalable Representational abstractionsSensor “eyes”Track Space
21 Optimal Racing LinesNot easy task, math/physics intensive and track dependentHow to overcomeLimit custom built tracks, only allow users to use predefined segmentsBoring, lack of variety for usersJust because pieces have racing lines, doesn’t mean an optimal race line will occur from sticking pieces togetherPredetermined segments, have predetermined racing lines
22 Race Lines Cont… Search for line of minimum curvature Does not account for car (width, weight), or speed. Is simply the most effective path along a trackVery quick, efficient and highly reliable.
23 How to do it…Initially put points equally spaced in the center of the track from start to finishIn sets of three points, gradually reduce the curvature by using the sum of the squares of the angles between them.
24 Points, and Vectors… Joined by vector AB, BC These vectors make up angle alphaApplying a small force to f proportional to alpha:a,b,c the points move in such a wayThat alpha is reduced. This process if repeated over and over, until an optimal path is produced
27 Surviving a Simulation Simulation AI very importantControls all the other things in a single player gameIs used as to show how the game development is “progressing”Overall quality of game play is based on how good the AI is
28 Design & Implementation Code wellCreate a PrototypeTestForce the AI to use the same inputs a player would useMake the AI do real-world logical things.Layer the AI DesignNo mistakes, logical names, comments, etc.Layering – as seen in the previous AI
30 What else can be done?Include a debuggerMake AI visible to players
31 Summary A Good AI System is made of Layers Mathematics Influenced Layers operate in parallelGoal To generate lifelike racing AI with ability to pass and force the player to react moreMathematics InfluencedOptimizing Best Race Line