Artificial Intelligence (AIW)
The purpose of this document is to give you a good procedure for developing good, working AIWFile containing Artificial Intelligence Waypoints files for rFactor 2 tracks. AIWFile containing Artificial Intelligence Waypoints files basically provide AI drivers the information required so they can properly negotiate their vehicles around the track.
Important note: During the creation process you’ll want to save often. It is possible to put the AIWFile containing Artificial Intelligence Waypoints Editor in a state that it can’t recover from. More often than not this is caused by incorrectly using a feature more than it is bug-related.
Here are a few hot keys that you’ll want to know:
- CTRL + \ Enters and exits AIWFile containing Artificial Intelligence Waypoints editing mode
- CTRL + SHIFT + Arrow Keys Slides the car – useful while placing things such as pit locations. Pressing the above combination plus the ALT key will slide the car faster.
- SHIFT + Arrow Keys Used to adjust racing lines and corridors at each selected waypoint. Pressing the above combination plus the ALT key will fine-adjust the line.
- Page-Up Swing Camera View
- Insert Cockpit Camera View
Also, there is NO undo function, so each change is permanent for the working session once it’s been made (and permanent to the file once saved). So, save often, keep a back-up of the last known good AIWFile containing Artificial Intelligence Waypoints file, and don’t be afraid to exit out without saving if something is not working the way you expected.
Track preparation and tips
There are a few things you’ll need to do before building up a fresh AIWFile containing Artificial Intelligence Waypoints for a new track:
- Make sure there is no existing AIWFile containing Artificial Intelligence Waypoints file – this can happen sometimes if you copy data files from an older track to the new one. It’s easier to start a new AIWFile containing Artificial Intelligence Waypoints file from nothing rather than trying to modify an older one.
- Make sure that some drivable surface is underneath world 0,0,0. With no garage locations defined, your car will appear at 0,0,0. If no surface is below the car when it loads you’ll enter free fall every time you click “Race.” If you have to, build a temporary “road” that leads from 0,0,0 out to the track. Once you define a garage location you can then remove this temporary road.
- Make sure that all the XSector GMTs exist within the scene – not having these when the scene is loaded, I find, will cause a CTD when trying to load the new track without an AIWFile containing Artificial Intelligence Waypoints file.
- Make sure you have selected ZERO AI drivers before loading the track – the only car you want loaded at first is yours (the player’s). You don’t want to add AI to your track until you have garage and pit locations for them, as well as at least the racing line plotted out.
- Set Damage to zero – this will prevent your car from overheating or suffering other damage that could disrupt the creation process.
- It’s often much easier to work while in Swing view.
So, you’ve got a good start on your track and you need to start driving around on it for testing. Following the above guidelines, you’ve prepared the track and have just loaded up in rFactor2 for the first time. The first thing you’ll want to do is to lay down the Main Path.
Drive out onto the track facing in the racing direction. Orient the car so it is in the middle of the width of the track. Now, in the menu click on “record a path”—this starts the recording process. Drive slowly around the track, being careful to keep the car in the middle of the track as best aspossible. If you’re in swing camera you’ll see blue way point icons being placed behind your car as you drive. Eventually, as you’re nearing a complete lap, you’ll see the very first way point placed at your start position—aim for it as you drive up to it. When you cross over it the menu will change, and you’ll be asked what path it was you just drove—select “add new path as main.”
Now that the Main path is placed you should add a path that defines the pit lane. The best place to start the pit path is at the point where a car would exit the racing line and turn to enter the pit lane. So, drive out to the place where you feel this would occur, orient the car in the racing direction and then click “record new path.”
Now, start moving forward slowly, again driving as though you were coming off the racing line and entering pit lane. Once on pit lane remember to drive right down the middle of the lane. Continue on as you exit the pits and enter back onto the race track, driving as you would if you were exiting the pits and entering back onto the racing line.
Stop the car and click “press to stop recording” when you reach the point where you want the end of the pit path to be. The menu will change. You’ll want to select “add new path and mark as 1st pit.” Now all you need to do is attach the pit path to the main path. Since you’re already at the end of the pit path it’s easiest to start there.
Click and drag a box around the last waypoint of the pit path. It will turn red. Now, click and drag a box around a way point that is just beyond the last pit path point (don’t select a point that is next to, or in front of the last point as it will not allow smooth transitions from one line to another). Both waypoints should be red now. Also, the menu has changed to the “Selected Waypoint Menu.” Expand the “connections” sub-menu and select “join as branch.” As long as you don’t get a message saying there was a problem the connection was made.
If the first two waypoints are still selected, click “unselect all” and then drive to the beginning of the pit path. Now, select the first pit path waypoint, and a waypoint that comes before it on the Main Path. Again, select “join as branch.”
At this point, it’d be a good idea to save the AIWFile containing Artificial Intelligence Waypoints file (by clicking “save waypoints” from the main waypoint editor menu), press ESC to exit the track, and then exit back to the main menu. If you want to continue working, load the track again (which now loads the new AIWFile containing Artificial Intelligence Waypoints file you’ve just made). At this point you can begin corridor, location and racing line work ...
The next thing you’ll want to do is “find corridors” from the main menu. AI use corridors to get information on the width of the track, what is a legal racing surface as opposed to an illegal surface, and so on. When you click on “find corridors” you’ll get a countdown as each waypoint is processed. Generally, the process usually takes only a few seconds.
Normally, you don’t have to do much to the corridors once they are run, but it is possible to use them to help the AI filter through narrow sections of track and enter tight turns—more on this below. For now, just run them as leave them as is. Once finished, it would again be a good idea to save the current version of the AIWFile containing Artificial Intelligence Waypoints file.
Garage and Pit Locations
The next task is to assign location waypoint that determine garage space for each car the track supports, as well as a pit stall for each team. rFactor2 supports up to 3 cars per team. The early rFactor2 tracks have support for 15 teams, 2 cars per team, for a total of 30 cars on the starting grid. With our latest tracks, we’ve increased the number of teams to 20, for a total of 40 cars on the grid. However, you can set up support for even more teams and cars if you wish.
You really have two choices here: you can either set up ALL the garage and pit locations now, OR you can just do the set up for team 1 so that your car is placed in the garage area instead of world 0,0,0 while the track is in development. You can come back and add the other locations at any time. For now, we’ll just do the first team so you get the idea of how the process works.
From the waypoint editor main menu select “set grid/pit/garage locations.” The menu will change, and you should now see an option for “add garage location” –select it. You’ll see a list of garage locations you can assign, up to three locations for each team. Position and orient your car so that it is where you’d like the car to appear when the track is loaded, and click “record pit 1 garage 1.” Now, slide the car a bit to where the team’s second car would be when it appears in the garage and select “record pit 1 garage 2.” If the team has up to three cars you can add the third, or you could start recording locations for the next team. Since we’re only doing team 1, select “exit garage loc” to return to the main menu. Again, a save at this point is advised.
The process for assigning a pit stall location for each team is similar. Position your car where team 1’s pit stall location would be. Select “set grid/pit/garage locations” again, and then “add pit location.” Finally, “record pit loc 1”. If you were setting up the stalls for the other teams you’d continue on. Again, for now, exit to the main waypoint menu and save again.
The driving lines are used as a base guide to help the AI navigate around the track. There are 4 types of lines we’ll be concerned with: “fastest”, “left”, “right”, and one custom line we’ll make ourselves— “BLOCK”. You can also create other custom racing lines for specific car types, but generally this is not necessary. Let’s start with the “fastest” line.
The best way to create the “fastest” (or the racing line) is to drive it as if you were actually racing the track, trying to set the fastest time possible with the cleanest driving. If you’re not a great driver you may want to enlist help for this. To begin, just start driving the track to warm up the tires and get a feel for it. When you’re ready to set a fast lap, click “path sub menu” from the main waypoint menu, make sure the current path is “fastest” and click “Record new best path.” The recording will start as you cross the start/finish line.
Drive as well as you can. If you have an off, or the lap wasn’t clean, don’t worry--you can record lap after lap. Every lap that breaks the previous best time will be recorded, and this becomes the new default. When you are happy that the best lap time you set was done on a clean lap you can stop recording. If you had a good lap time, but the driving wasn’t clean, you can reset the best time to start over again. Again, once you’re satisfied, stop recording, go back to the main waypoint menu and save. You’ll want to completely exit the track and reload it (if you plan to continue working) so that the changes take effect.
Once the track is reloaded, the first thing you’ll want to do is check that the line is smooth between the last and first waypoints of the Main Path. Often, those two points don’t line up linearly, and it will cause a kink in the racing line. If you don’t correct this it will act as a braking point for the AI. To fix this, make sure the fastest line is visible (“path sub menu”, “visible/action path” should be set to “fastest”) and then drive to where you first started to record the Main Path. The white line is the fastest line. If you see a kink in it, select several waypoints on either side of the kink, open the “manipulations” sub menu and select “normalize curve.” The white line should become smooth. “Unselect all” the waypoints and save.
Now, you’ll want to make sure the pit path that branches smoothly off of the fastest line at both ends. If it doesn’t, the AI will make slow, aggressive turns to try to get onto or off of the pit path, which looks incorrect and can cause accidents. Let’s start with the beginning of the pit path. Select a few waypoints at the beginning of the path and, using SHIFT + Arrow Keys “slide” the path across the track so that it blends smoothly with the fastest line. Once done, unselect the first two waypoints of the pit path, select several after the remaining selected points, and click “normalize curve.” The path should now have a nice, smooth blend off of the racing line and onto the pit line. Now follow the same procedure for the other end of the pit path. When done, save. Again, you’ll want to exit the track and reload it.
When the track is reloaded, if you make the left or right lines visible (“path sub menu”, “visible/action path” (or “visible path 2”, or “visible path 3”), you’ll see they’ve been auto-generated for you. Normally, you don’t need to do anything else to these lines, although it’s always good to make sure the pit path blends smoothly onto and off of each of these, just as you did with the fastest line.
If you want the AI to make blocking moves, you’ll need to set up a “BLOCK” path. To do this, click “path sub menu”, “name a new path”, and enter the name BLOCK. Now, select the BLOCK path as the “visible/actionable path.” You’ll then “record a new best path” just as you did with the “fastest” line. This time though, you’ll want to drive each lap as if you were blocking someone from going inside you to pass as you enter turns, or from going offline to pass you down a straight. Again, try to drive cleanly as you do this (don’t worry, it takes some practice to be able to drive offline in this manner for an entire lap). Don’t expect the lap time to be as quick as it was when you were driving the normal racing line. When you’re done, save, reload the track, and smooth out the pit path transitions for the new BLOCK line.
Save and reload again.
Grid, Teleport and Safety Car Locations
At this point, if you haven’t already set up the rest of the garage and pit locations, you should do that now (assuming the art is done so you can place them properly). Also, now is a good time to mark the “Special Slowdown” waypoint. “Special Slowdown” is typically the waypoint just before the pit lane officially begins (a white line normally marks them, and the Pit-In XSector should be placed in accordance with that white line). When the AI “see” this waypoint they know they HAVE to brake and get down to the pit lane speed limit. Unselect this waypoint.
The next waypoint to select and mark will determine the “Teleport Spot.” This is the location all the cars will jump to if you skip the formation lap. This should be a good distance away from the start/finish line, especially on an oval. Once tagged, unselect this waypoint and save. We can mark the safety car locations—we’ll need two of them. From the main waypoint, select “set grid/pit/garage locations”, then select “add aux location.” The first point you’ll place is where the safety/pace car would be if you were doing a formation start. Usually, this is just past the start/finish line. Drive to that location, orient the car in the racing direction and then click “Pace Car Formation Start.”
When that is done, you’ll set the location where the safety car would normally be parked on pit lane when not in use. This should be off the normal line the AI use as they drive through pit lane, but it needs to be accessible so the safety car can pull out and merge onto the pit path when a caution comes out. Drive to a suitable location, orient your car as the safety car would be when parked, and then click “Pace Car Pit Start.”
As always, now would be a good time to save.
Finally, you’ll set up the starting grid locations. There are two methods for this--manual and automatic. If you want the grid automatically here’s the procedure:
- Click “unsupported/test options” from the main waypoint menu
- Click “Auto grid Gen Off” – it should turn On
- Click “back”, and then click “set grid/pit/garage locations”
- Click “Add start location”
- Drive out onto the track and stop the car where you want the first grid position to be, with the car facing in the racing direction
- Click “record start loc 1”
- At this point, exit back to the main waypoint menu, save the waypoints, exit the track, and then reload it.
- Now, return to the AIWFile containing Artificial Intelligence Waypoints editor and save the waypoints again. A full grid should have been generated based off of the location of the first grid spot, using the left and right lines to guide them.
The more likely situation though is that you will need to place grid spots manually based on art.
Often, tracks have painted lines marking each starting location on the grid. If this is the case for the track you’re working on here is the procedure:
- Click “set grid/pit/garage locations”
- Click “Add start location”
- Click “Add start location”
- Click “record start loc 1”
- Now, slide or drive the car to the second starting location, properly orient it, and click “record start loc 2”
- Repeat the process for the remainder of the grid’s start locations.
Keep in mind that typically a tracks grid is arranged with odd numbers on one side of the track (often the outside), and even numbers on the other.
A final note on grid locations: notice that there is also an option to “add alt start location” (s). This is normally used in NASCAR-like racing where the grid begins a formation lap on the pit lane. The cars line up on the pit lane, follow the pace car for a lap, and then begin the race while in motion (called a “rolling start”). If you’re working on a track that supports this sort of start you’ll want to place these alternate start locations using the same procedure as with the normal locations.
Two Final Things
There are two final tasks you need to do to complete your AIWFile containing Artificial Intelligence Waypoints file properly. The first is to “Simulate Fuel Usage”. You do this by clicking “unsupported/test options” from the main waypoint menu, and then clicking “Simulate Fuel Usage”. While the AI keeps track of fuel during the race, setting this value is used in the UI to show the estimated fuel requirements.
The last thing you should do, just to make sure all the auto-generated elements have been handled properly by rFactor2, is to “save waypoints”. Exit the track, reload it, and then “save waypoints” again.
That’s it. At this point you should have a fully functional AIWFile containing Artificial Intelligence Waypoints that will allow players to race against a full field of AI drivers. There are a few things you can do though to help the AI drive better, such as corridor manipulation and specific lines for certain types of vehicles, which I’ll discuss next.
So, you did all this work, but the AI are having some trouble getting around a tight turn, or are running wide because you drove the racing line with a car that has more grip. There are a few things you can do to help, and a few things that ISI are doing that will help even more.
Let’s take the chicane at Monte Carlo as an example. This section of the track is very tight, and often the AI was having trouble getting through it cleanly. Much of the problem here was that the AI would sometimes try to pass going into the chicane, thus forcing a two-wide situation. To help eliminate this we used the corridors to create a choke point leading up to the braking zone for the chicane, which helped the AI get single file. Here’s how it was done:
- Make sure there are no visible/actionable racing line currently displayed
- Click “show/hide menu”
- Click “Show Corridors”
At this point, you should see red and white lines extending out from each waypoint. These mark the left and right width of the track. You can adjust these by using the SHIFT+Arrow combinations (left and right for the red line, and up and down for the white line). Pressing ALT while adjusting these will make more fine adjustments.
In the case of the Monte Carlo chicane, the white lines were slowly tapered in from before the brake zone began up until the turn in for the chicane. What this did was cause the AI to believe the track was getting more and more narrow, thus forcing them to try to go into the turn in single file (as much as the situation would allow).
This is not a very time consuming tweak, and it can make a lot of difference for tracks with problem turns such as this.
Also, many times, while cars with similar characteristics can use the default racing line you created, sometimes other cars may have issues with it and not drive to their full potential. In this case you can create a unique racing line for certain car types. This line is referenced in the talent file for each car, and those cars will use that line.
To create a unique line follow the procedure outlined above when you created the BLOCK line. This time though, give the line a name you can recognize for that car. In the case of the Skip Barber you might use something like, “Skippy_RacingLine”.
Select the line as the “visible/actionable” line, click “record new best path”, and race the track using the car in question. When you’re happy, stop recording and “save waypoints”. Now, from the main waypoint menu click “Edit Driver Stats”.
You’ll want to select “default” as the driver at the top of the Driver Edit menu. Now, for “current path”, select the path you recorded, and the click “save”. The AI will now use this alternate racing line when they are driving the car in question.
Please note, ISI is currently developing a new, more robust form of AI learning so that the AI will learn how to drive each track as best as possible. While this work is still in progress it is proving very successful in testing. This will make the tweaks suggested above not as necessary as they currently are, if they will even be required at all. Stand by for more info on this.
My hope is that the above “tutorial” will assist you in the development of tracks for rFactor2. However, this is by no means a comprehensive guide to using the AIWFile containing Artificial Intelligence Waypoints editor; so, if you have any questions please make use of the “modders” section of the rFactor2 forums.
Also, please keep in mind that ISI is constantly working to improve not only how rFactor2 performs during gameplay, but also how the assets are set up. In both cases, these may cause the procedures described above to change. Again, the “modders” forum will be a good place to get information about these possible changes.