What I Learned Making AIW for Formula 1 Series

Discussion in 'Modding' started by dosequis56, Oct 10, 2022.

  1. dosequis56

    dosequis56 Registered

    Joined:
    Dec 24, 2021
    Messages:
    133
    Likes Received:
    48
    This thread contains what I have learned trying to build an F1 series for racing with AI in a family racing mod I will post finding in a series of replies to try and keep topics separated and allow to add replies as I learn more things or as folks contribute their insight.
     
    solerpalau, Beef36, FuNK! and 6 others like this.
  2. dosequis56

    dosequis56 Registered

    Joined:
    Dec 24, 2021
    Messages:
    133
    Likes Received:
    48
    The RCD file matter to how the AI will run your track. The StepDistance and StepSpeed values control how far ahead the AI will look at various speeds. The StepDistance is distance multiplier for each step and the value for each step is the speed of the car that will trigger this step to be used and the multiplier to StepDistance to be active. A SpeedStep value of 10.0 tells the AI to use THIS step at speeds of 10 meters per second and so on. If your SpeedStep values are high, the AI can look several waypoints ahead to determine the corner curve it takes which can result in driving through walls or driving off the track even if your waypoints and lines are fine. After lots of experimentation at Monaco (where the AI was smacking walls left and right), I chose the following for the F1 Hybrid-22 cars:

    StepDistance = 2.5
    StepSpeed1 = 10.0 //8.0
    StepSpeed2 = 15.0 //12.0
    StepSpeed3 = 20.0
    StepSpeed4 = 33.0
    StepSpeed5 = 45.0
    StepSpeed6 = 60.4
    StepSpeed7 = 70.9
    StepSpeed8 = 80.0

    The value of DrivingLine tells the AI what paths to choose while racing. Note that for formation laps and caution laps, the AI always seem to your path 2 and path 3 (LEFT and RIGHT). For single file caution laps (such as in F1, they seem to prefer RIGHT, but also will occasionally jump into LEFT (no idea why). For the F1 Hybrid-22 cars I used:

    DrivingLine = FASTEST,FAST_ALT1, FAST_ALT2

    Now when I work on track AIW, I decide if I need alternate racing lines to make the racing more interesting (like getting the AI to fan out etc.)

    For the other settings, I experimented with seeing the AI run decent laps at Monaco and chose:

    CorneringCaution = 50.0
    OverSteerThrottleReaction = 55.0 //-85.0
    UnderSteerEffectOnThrottleMulti = 130.0
    UnderSteerEffectOnLineMulti = 100.0
    FearOfWalls = 99.0

    The other thing that can really affect racing with the AI is the collision mesh definition for the vehicles. At Monaco, I was seeing AI cars locking wheels because the collision mesh for the car had openings between the wheels and body (like all open wheel cars have). To fix this, I modified the collision mesh to make the collision zone square and now the AI cars avoid this type of contact and back off vs. locking together if there is no room (and at Monaco, there is no room anywhere).

    Once these things are good, we can move onto fixing the AIW for each track you want to run in your mod or series. Note that I did a bunch of other things to the vehicles to get the cars to run more realistically as in real life, but that was not to make the AIW work.
     
    atomed likes this.
  3. dosequis56

    dosequis56 Registered

    Joined:
    Dec 24, 2021
    Messages:
    133
    Likes Received:
    48
    Each track comes with one or more configurations each of which contain AIW. You can definitely create a different AIW for a different series on the same track, but I am just going to deal with F1 configurations and AIW. Each configuration has a GDB file that defines the properties for racing on the track and each GDB file has an AIW file. One thing that may matter to your AIW development in the GDB file is FormationSpeedKPH which is pretty self explanatory. The AIW use this value for both formation laps and safety car laps and a value too high will make a safety car pure madness, especially if the pace car is slower (such as in F1) and it slows heavily in the corners trying to maintain a very high speed (and you rear end the field as they brake hard). Safety car laps are so tight that it is almost impossible to avoid rear ending the guy in front if they brake hard. I have yet to find a solution to the spacing of the cars.

    The AIW file has a few properties that define how the AI cars drive, but mostly contains sets of coordinates (waypoints) and paths (driving lines, formation lines, etc.). There are a few different types of waypoints (ignoring special points, like teleport, aux):
    • The driving line
    • The pit line
    • The pit spots
    • The grid spots (standing starts)
    The driving line and the pit line have fixed spacing when they are generated (i.e. a point every 'n' meters of track)

    The AIW file has lines, where each line is the computed as distance from the driving line or pit line waypoint. You can define custom lines, but there are some required lines if you want offline racing to work.
    • FASTEST is the default racing line and is line 1 (index=0 in the AIW file)
    • LEFT is the left side formation line and is line 2(index=1) (NOTE: formation line is also the safety car line)
    • RIGHT is the right side formation line and is line 3 (index=2)
    If you want the AIW to block overtakes, you can also have a BLOCK path (might need to be at index=3, but not sure). An interesting use of the BLOCK path is actually to do the opposite at a place like Monaco where overtakes are so difficult (so basically, BLOCK concedes the best line).
     
    atomed likes this.
  4. dosequis56

    dosequis56 Registered

    Joined:
    Dec 24, 2021
    Messages:
    133
    Likes Received:
    48
    To help map AIW concepts to the file properties, here is an example waypoint:

    wp_pos=(-361.7040,-22.4721,1872.8100) // ID=0 n/a
    wp_perp=(0.8377,0.0002,0.5461)
    wp_normal=(0.0103,0.9998,-0.0161)
    wp_pathinfo2=(0,-2.9197,0.0252,51.4918)
    wp_oriantation=(0,0.0205,2.5667,-0.0064)
    wp_pathflags=(0,0)
    wp_pathinfo2=(1,-4.6128,0.0266,51.1414)
    wp_oriantation=(1,0.0213,2.5762,0.0026)
    wp_pathflags=(1,0)
    wp_pathinfo2=(2,3.2704,0.0142,52.9063)
    wp_oriantation=(2,0.0184,2.5675,0.0011)
    wp_pathflags=(2,0)
    wp_pathinfo2=(3,3.0399,0.0139,52.7473)
    wp_oriantation=(3,0.0183,2.5760,0.0026)
    wp_pathflags=(3,0)
    wp_width=(8.575,6.900,11.000,9.852) // road left, road right, far left, far right
    wp_dwidth=(11.000,9.852,0.000,0.000) // collision left, collision right, cut left, cut right
    wp_lockedAlpha=(0)
    wp_test_speed=(51.49182)
    wp_reverb=(0)
    wp_score=(100.049)
    wp_wpse=(0,0)
    wp_branchID=(0)
    wp_bitfields=(0)
    wp_pitlane=(1)
    WP_PTRS=(1446,1,1602,0) // ID=0

    I will not go into all of the properties and there are probably track builders who know the details more than I do. The first three properties (wp_pos, wp_perp and wp_normal) define the waypoint coordinate. There are three corridors defined in the AIW and they are important. Corridors are defined in wp_width and wp_dwidth. I treat far left, far right and collision left, collision right as the same thing, not sure if there is some difference.
    • corridor
    • collision corridor
    • cut corridor
    There names really define what they are. The 'corridor' is the width of the raceable track from the waypoint. Note that the corridor extends left and right from the waypoint based on the orientation, so orientation matters. The 'collision corridor' is the absolute limit of the track that the AI MUST avoid to prevent having a collision. The 'cut corridor' defines the limit the AI can cut the angle of the corner. When you modify AIW, corridors are the mechanism you use to tell the AI to choose proper entry into a corner etc. For example, you come down a straight and the cars HAVE to get single file for a corner, the corridor will tell the AI to do that and avoid a mess in the corner. The corridor and cut corridor can be modified in the MODDEV launch of rfactor. I did not find a mechanism to modify collision corridors so I wrote a tool for that.

    The properties wp_pathinfo2, wp_orientation and wp_pathflags define each line at each waypoint location. The first value is the line number (0, 1, 2 ...) which map to (FASTEST, LEFT, RIGHT ...). These properties can be modified in MODDEV launch of rfactor. The line can be moved left and right and the orientation can also be adjusted (the way the car is pointed when running that line and reaching that waypoint). There is also a property that will set a speed adjustment for the line.

    wp_pathrecrad=(0,-0.0251)

    This property is very powerful as it can adjust the AI speed to make more sense when it hits a line that bends too much and thereby becomes jagged to the AI. I have seen a lot of cases where the AI is much slower than they need to be through a corner. The first value is 0 for a speed adjustment. The second value is the speed adjustment where a negative value makes the AI go faster than the computed speed. Note that these values are also set in MODDEV launch of rfactor.
     
  5. dosequis56

    dosequis56 Registered

    Joined:
    Dec 24, 2021
    Messages:
    133
    Likes Received:
    48
    There are videos for creating lines (driving them) and adjusting the start-finish line where the start and end of the recorded path intersect and then for adjusting the pit entry and pit exit. You will also need to learn how to adjust the corridors in the AIW editor (MODDEV of rfactor) and do speed adjustments (shift-up-down). For all adjustment types, also holding 'alt' with 'shift' makes the adjustments smaller. You will also need to adjust corridors which uses the same shift-arrow commands but without a LINE selected. Adding 'alt' works here too.

    When you adjust the AI lines, you need to drive the track and become good enough to have realistic corner entry and exit. You use this to measure against the AI to see if they are brake checking, slowing too much etc. To give you an example, I was racing with AI as SPA in an F! car and the AI would touch the outside grass coming up the hill (not a problem in itself) and brake checking there too. I would pile into them if following. So I adjusted the line and did a speed adjustment to the line at the waypoints where I was seeing the issue and it was fixed. It is usually just a few points. You can see the calculated speed in the AIW editor and you will see this very slow computed speed; so it is pretty obvious. Move the line a bit and it you can't fix it, make a speed adjustment.

    The LEFT and RIGHT paths will allow formation and safety car laps to work. If they cross or are not defined right, the AI will stop, hit each other etc. etc. on formation laps. Since they aren't racing lines, you do not need to worry too much about speed calculations.

    You will iterate through a series of racing watching your AI behavior and continue to make adjustments until you feel that passing is happening and collisions make sense. If you have AI entering the corners at a bad angle trying to pass and making a mess, use 'corridor' adjustments. If they are hitting walls, you may need a collision corridor adjustment which cannot be done with the AIW editor. Hitting the walls may also be due to the cars cutting the corner and you should evaluate your RCD file. Part of the iteration will also involve running some races with AI at the back of the pack (where you can see the fun).
     
    atomed likes this.
  6. dosequis56

    dosequis56 Registered

    Joined:
    Dec 24, 2021
    Messages:
    133
    Likes Received:
    48
    Waypoints are created at fixed spacing on the track. However, there is nothing that prevents tighter spacing at some points of the track. I found that adding MORE waypoints at 'hairpin' corners of the track (like at Monaco) helped the AI make these tight corners and run smoother through them. Basically, more waypoints means less 'jagged' turns (as seen by the AI sawing on the wheel). For Monaco, it was almost impossible to have them make the hairpin corner and not drive over the high inner curb cutting the line between the waypoints (vs. driving a smooth arc). There is no way to add a waypoint that works, so I wrote a tool for that. The tool I wrote is given a range of waypoints and inserts a waypoint between each point in that range and does a relative calculate of all lines, orientation etc. for the new waypoint. The intention is to effectively define the new point EXACTLY in between the two points. Then, you go back into the AIW editor (MODDEV) and make adjustments to the lines and orientation. I found using the tool in the AIW editor to adjust the orientations of a set of points worked pretty well vs. adjusting each point one by one.
     
  7. dosequis56

    dosequis56 Registered

    Joined:
    Dec 24, 2021
    Messages:
    133
    Likes Received:
    48
    The main problem I have been unable to improve once the AIW is correct is safety cars. I see a series of issues which may come down to one main issue (note sure). The spacing of the cars in a safety car is VERY tight, which might be fine for stock cars when getting ready for the green flag but doesn't work well for road course racing and F1 where pace speeds are higher. Then you get the 'you go, no you go issue' which I believe may be caused by the tight spacing where there is not enough room for the car to pass and line up in its correct spot. They start to see-saw back and forth. A safety car is often race over in rFactor. I have tried to adjust lots of properties and have seen no real improvement.
    The 'turn 1' syndrome is also still there when the AI dive bomb into the first corner and then can't make it through the corner 2-3-4 wide and basically stop. Not as big a deal as the human just learns to tip-toe the first few corners and then go racing. For Monaco, this problem continues through the hairpin and then they get going. I would say corridors should fix this, but I have pretty narrow ones at Monaco and they still can't get themselves single file without this checkup in the first few turns.
     
  8. Stockers

    Stockers Registered

    Joined:
    Nov 15, 2016
    Messages:
    111
    Likes Received:
    40
    How did you work out the values of the stepspeeds?
     
  9. dosequis56

    dosequis56 Registered

    Joined:
    Dec 24, 2021
    Messages:
    133
    Likes Received:
    48
    A little bit of math where you related the step distance to the waypoint spacing in the tracks where you see the biggest problems and then a lot of experimentation. My my case, the track was Monaco where I worked with the values until the AI stopped trying to cut the corners thru the walls and still avoiding them having no look ahead. For Monaco, the lower speed steps mattered the most since a lot of the tight corners at low speed.
     
    Emery likes this.
  10. RoboCAT10

    RoboCAT10 Registered

    Joined:
    Oct 18, 2014
    Messages:
    639
    Likes Received:
    114
    Where do you find collision mesh?
     
  11. lagg

    lagg Registered

    Joined:
    Oct 1, 2012
    Messages:
    3,043
    Likes Received:
    1,958
    In the car, but it's not mandatory.
    If the car doesn't have, the collision model is generated automatically by rF2.
     
  12. dosequis56

    dosequis56 Registered

    Joined:
    Dec 24, 2021
    Messages:
    133
    Likes Received:
    48
    Each vehicle can have a collision mesh that defines the area of the car. It doesn't have a fixed name but is usually named xxxcollxxx.gmt or xxxcollisionxxx.gmt.

    eg. NR2019_C_COLLISION.gmt
    eg. asmg_fh22_coll.gmt
     
  13. SharD

    SharD Registered

    Joined:
    Apr 17, 2019
    Messages:
    374
    Likes Received:
    437
    Can you safely delete a faulty collision model from a mod, then?
     
  14. dosequis56

    dosequis56 Registered

    Joined:
    Dec 24, 2021
    Messages:
    133
    Likes Received:
    48
    I have never tried that, but it seems to be implied above that one is generated by the game if note defined.
     
  15. Lazza

    Lazza Registered

    Joined:
    Oct 5, 2010
    Messages:
    12,382
    Likes Received:
    6,600
    @dosequis56 @SharD functional, but probably not ideal. You can see the generated shape in devmode with the right keypress(es) (I think maybe Ctrl-H a few times, but I'm probably remembering wrong, and some have changed). Usually a pyramid type shape, avoids nasty track/kerb collisions but car interactions might not be great.
     
    dosequis56 likes this.

Share This Page