Tutorial on making 2-way traffic (or other) AI lines and layouts

First step for making the 2-way lines is checking out the road and surfaces.ini for impending problems with the side lines. One way for that is to load the track with some layout that already has AI lines and have a look at those. May require disabling of "Origin shift" in CSP settings > "Graphic adjustments". If the red sides follow exactly the border between the asphalt and the green or brown stuff then most probably you will have the same side lines automatically generated from the game after your attempt.
Clipboard01.jpg


Another way of checking is to confirm the names of the objects that are physics. Those have number for first symbol in the names (0 doesn't count). 1ROAD next to 1SAND when the surface "SAND" has "IS_VALID_TRACK=0" tag in "..\AssettoCorsa\system\data\surfaces.ini" or in the layout's "surfaces.ini" means the side line will be created on that border.
Clipboard02.jpg
Clipboard03.jpg


When the objects for physics are correct you need to prepare the new layout's structure. In Windows Explorer open the track's folder (fastest way - right-click or use the three dots next to the track's name in Content Manager). In there create new folder (i.e. "2way") and while empty - copy that into "ui". Then from "ui" or some of the other track's layouts select and copy the three .png and the "ui_track.json" into the empty "..ui\2way\" folder. Edit the contents of "ui_track.json" to reflect the changes in this layout. Avoid putting the new name entirely different than the other names of the track's layouts but add few words after the old name. When done editing that re-open CM and see if the new layout shows up for selecting.
Clipboard04.jpg
Clipboard05.jpg


Then proceed to creating the file structure - copy the "data" folder and map.png from some of the existing layouts and paste those into "..\<track name>\2way\". Make a copy from some of the other "models_***.ini" for that track or if there are none you need to create new in the track's folder ("..\<track name>\") and name it "models_2way.ini" to match the name of the layout's folder. If you are making new - open it and create a paragraph

[MODEL_0]
FILE=euphoria_hillside_park.kn5 ;the actual name of the kn5 model in the track's folder;
POSITION=0,0,0
ROTATION=0,0,0
Clipboard10.jpg


After that load the new traffic layout in "Practice" mode. When all of the necessary models are present the car will be functioning and positioned correctly and you will be ready for drawing the fast_lane. Notes on the car choice - large cars with longer wheelbase are more stable but the lines drawn with those have longer segments and in tight turns that sometimes becomes too obvious later with the AI cars. Drawing the line at racing pace is not necessary and two lines drawn with different cars at different pace work the same provided the lines have the same geometry. So choose a car that has small enough turning circle, smooth and broad torque band, big enough suspension travel and gripping tires to give you the best traction and stability and then drive it like a grownup. Choosing a car with weak engine allows for relaxing your feet by flooring it for long enough during the drive and that matters a lot when it takes more than 1 hour for driving the line on a long road.

Next on the list - choosing the actual route. The simpler - the better. Avoid as much as possible: overlapping the line by driving again in the same lane; crossing the paths of the AI; narrow passages between walls or near obstacles.
Find the best places for the U-turns with road tagged as "IS_VALID_TRACK=1" wide enough to accommodate the turning circle of most cars in the "street" class. On a long road or large road grid use the "map.png" file to actually draw into it the arrows to guide you where to turn and color-code those if it's multi-lane and you need to make another parallel loop. So your first stab at making the traffic is a drawing over the "map.png" and then practice run on which you confirm on track where and how to turn.

Settings of CSP and other for the time of driving the new lines - the entire "New AI behavior" module should be turned off, "Origin shift" in CSP settings > "Graphic adjustments" should be disabled. Deactivate all Python apps except Sol controls.

When all of the above is done and you feel there's enough energy left for the long haul - start the engine. By that I mean choose the starting point of the line on some straight bit with distinct object next to the side which you take as reference. YOU NEED TO STOP THE RECORDING AT THE END OF THE DRIVE JUST BEFORE YOU REACH THE STARTING POINT. This method doesn't need the first timing gate to form a "start line" and to begin and close the recording there. I use "start pits" to record the line from anywhere I fancy to anywhere I decide to stop.
Clipboard06.jpg

On multi-lane traffic it simply is the only way for creating the parallel lines. On A2B hill-climbs it's the easiest way to make the AI cross the finish line. The drawback - after completing the drive and renaming the "pit_lane.ai.candidate" to "fast_lane.ai" the game takes it's time to evaluate it upon loading which takes as long as the time to actually render the line upon exiting the session. So if the rendering needs 2 hours it will take twice that when making the line from "pit_lane.ai.candidate" and you need to interact in the middle of that wait. In conclusion - to save time you may consider the option to start the 2-way just before the timing gate as long as you don't need to pass through it again in the same direction for making another round. In that case using the standard "start recording" in the "AI" app will spare you the wait for loading the raw line and the rendering will be done upon exit of the same session. To see the location of the timing gate you have no other option but to use 3DSimED to load the relevant track's models prior to the attempt.
Clipboard12.jpg

*To make things more interesting the author in this example had the track encrypted and for that the wire-frame view is necessary. The positioning of these two gate objects would prevent making of the traffic that I've done using the "start pits".

The timing gate may not be on the map, may not be in the place that the map says it will be, or it may not be present at all. If any of this and without checking - you will waste a lot of time blindly driving around just to find out that timing doesn't work and the recording of the traffic you want is never going to happen. In case you need the gate to be somewhere else or if it simply is missing in the track you can create it by placing by the sides of the road two primitives in 3DSimED. Boxes with 1m sides are fine and the names should be "AC_TIME_0_L" and "AC_TIME_0_R" for the left and right side respectively. "Plugin Export" that as "gate.kn5" and make it load by adding a paragraph into "models_2way.ini". Now, if the track already has those objects there is a big difference whether you put the new "gate.kn5" model last in the queue or first. Put it before all others as [MODEL_0] to make it work and observe the proper sequential numbering of the next models.

But if you are like me and want to get straight to it - use the "start pits" and just drive the route that you want. Just remember the place of the start and on the second approach to it click "recording" to stop the process before you reach the starting point. After exiting that session you will find a single "pit_lane.ai.candidate" in "..\<track name>\2way\ai\" folder.
Clipboard07.jpg

Rename it to "fast_lane.ai" and load another "Practice" session. This time loading will be slowed down by the raw line that you want to render. Be patient and don't terminate "acs.exe". If you like to have the PC available for other tasks use "Alt+Tab" or "Ctrl+Alt+Del" to make the "Desktop Manager" of Windows re-gain control over the screen.

After the loading is complete you need to use "start pits" again and depending if you intend to actually use the "pit_lane.ai" or a duplicate of the "fast_lane.ai" you may want to drive the good short guiding line into and out of the pits. When that is done click "recording" to stop the process and exit the session. That's when the actual usable lines are made by the game. The good result is two new .candidate files which need to be renamed by removing the ".candidate' from the names. The initial "fast_lane.ai" needs to get out of the way and for safekeeping you may pack it into a zip.

There are two scenarios for "pit_lane.ai": 1. using the short line that only covers the pit area or 2. making a copy of "fast_lane.ai" and renaming that copy to "pit_lane.ai". That gives the opportunity to scatter the pits along the route and make the AI join more naturally for a street driving. But when you have all cars starting from the pits using the duplicate "fast_lane" has no benefits.

If you think that's all - it's not. For most of the AI to work with the line there has to be some track-specific hints. A simple template for creating such "..\content\tracks\<track name>\2way\data\ai_hints.ini" file is

[HINT_0]
START=0.001
END=0.999
VALUE=0.8

[BRAKEHINT_0]
START=0.001
END=0.999
VALUE=0.9

[MAXSPEED_0]
START=0.001
END=0.999
VALUE=160

[DANGER_0]
START=0.001
END=0.999
LEFT=0.6
RIGHT=0.6

From those paragraphs most likely [HINT_**] and [MAXSPEED_**] would be of use, the first telling the AI that each corner radius is shorter than the look-ahead estimate (i.e. factor of 0.8) and the second - not to exceed the defined speed. Hints can work in combination and be multiple of the same kind. The numbering is [HINT_0], [HINT_1], [HINT_2], etc. and the "START=***" and "END=***" determine the points on the spline in form of percentage length from the starting point. It is displayed on the "AI" app but with a long splines you might want to use the "DRS zones" app instead to avoid CPU overload.
Clipboard09.jpg

The way I find most effective for tuning the hints is to load a well-developed car in "Hotlap" mode and enable the AI (Ctrl+G and Ctrl+C) so I can watch and listen for problems. If the AI resembles human driver then that part of the course is ok. If not I take note of the positions and edit the hints. Testing of the line is not complete without a Track day with AI flood. Before judging that some line is good or bad consider this: some AI cars experience difficulties with new AI flood when spawned at speed in the highest gear and have to downshift fast without any hesitation. Instead of doing it as expected many AI just can't engage the clutch. Here's what solves this issue: unpacking of car's data and enabling the unpacked data as default by renaming "data.acd" to "data.acd1", then edit of "drivetrain.ini" to have [AUTOCLUTCH]
MIN_RPM=100
Provided there's no other problems with the car's physics that makes it go without a hiccup. Additional benefit of using the unpacked data is the option to train that AI better so it doesn't hit the walls due to cutting corners or missing the turn.

Not essential but nice to have are F3 track-side cameras. The positions and directions of those are tied to the spline length and you can't simply use the old "cameras.ini" from another layout. For making the F3 cams I'm using the "Custom Shaders Patch debug app Advanced"
Again by enabling AI and setting [MAXSPEED_0] low enough I'm able to go round the course and in one lap to position all the cameras so the cars remain in frame later on. For making the cams I usually let AI drive some wide car with less body roll - like a Hummer in case of wide roads, so with F5 and some rotation I can reach over or near the edge of the road. Thanks to LeBluem aka @Please Stop This for making the useful tool.
Additional note on the cams - since v0.99k the app offers "new auto cams" mode of recording and it works very well for making huge sets for long lines when some conditions are met: the timing gate "0" should be present and at the exact spot where the line begins, you set "min_z=0" and "max_z=1", in CSP settings disable "New AI behavior" module and disable "Use double precision physics", in "Hotlap" or "Track day" session position the cams by selecting F5 and looking at the rear quarter close to the road edge without going into some buildings and other obstructions, at height of more than 2 m above ground. To add variety to the set you can change the "IN" and "OUT" while the AI does the driving. For wide and long straight roads - bigger distances between cams, for narrows and twisties - shorter distances. If the AI speed is limited that also calls for shortening the "IN" and "OUT". If "IN" is bigger than "OUT" cams show more the front of the cars approaching, if "OUT" is bigger - more of the rears is in the shots.

Let me know if splitting the opposite lanes is interesting for you and I will add more info. And don't hold back if you see the results of the attempts exceed your expectations - share the layouts with us!
 
Last edited:
The AI Dev app however can show the line and its borders correctly.
If you wonder what's the reason AI app to work strangely - check CSP settings and deactivate for the time being "Origin shift" in "Graphic adjustments". It does a good job of stabilizing textures rendering on big tracks but also causes the AI app to show misplaced lines. It also may be the reason for "Ctrl+I" not working on occasion. Can't vouch for that last one as I always drive without the ideal line graphics.
Saving the resampled line took so long I went to sleep. This morning the new line was saved
If you look at the time stamp you can calculate the rate of rendering. Was I correct with my estimate about the 50km/4 h ? Was it 72 km - 6 h? What generation CPU and what single core GHz on your PC?
Does AI flood work good with the new line or the cars are spawned stationary?
 
Last edited:
Origin shift is already switched off. This feature does break AI Dev app's line, but the coloured arrow AI line should not be affected by it. On some shorter tracks I can turn Origin Shift on and the Dev app lines would move away, but the arrows still show as intended.

I don't remember exactly when saving of that 72km line started. I'm sure it took less than 3h, which is not as bad as 6h/72km, but still annoying. My CPU is Intel 6700HQ.

The line works well with AI Flood.
 
Last edited:
synthetic fast_lane for Union Island
Edit: much sooner than expected. ~12 min for loading in ksEditor of 19.5k vert line ~37 km. Saving it without resample ~15 min.
The primary control of AI file processing time appears to be the range of coordinates it covers, not its length or number of samples. A short line located near the origin can be loaded, resampled and saved instantly. The same line moved a few km away from origin would take way longer during those operations. For a big track like the Targa Florio, a two-way traffic file is almost as big as one-way racing one, despite the line being twice as long.

I believe ksEditor is computing some kind of spatial grid/tree/index in a very inefficient manner. This structure must cover the range of AI line samples and the origin, and its density/precision is hard-coded. The bigger the bounding box, the longer it takes to do this. Union Island is only a few km across, hence the low processing time.
 
Last edited:
Well, this is getting really weird.

I scaled down the 72km line to 5% of its original size, imported into ksEditor, resampled to 1dm per sample, then scaled the saved file back to the correct size. Every operation was fast, and the new file works.

If the additional data generated was a spatial index, this should not happen.

I still have a question about traffic. How to limit the speed of a car?
I created ai_hints file and changed [MAXSPEED_0], but it didn't help(
If START is 0.0 and END is 1.0 the MAXSPEED in km/h should apply to the entire AI line. Double check you're creating the file in the correct folder.
 
While testing for rendering times I also found out that trucks with colliders and correct dimensions in "car.ini" need ~1.8 m on each side of the fast_lane.ai to work correctly.
Which value in car.ini controls vehicle dimensions in the eyes of AI? I've never worked on car mods outside skins so I might be missing something obvious. But looking at the car.ini of a few cars, including the traffic tank truck, I don't seem to see anything related to vehicle length/width/height.
 
Which value in car.ini controls vehicle dimensions in the eyes of AI? I've never worked on car mods outside skins so I might be missing something obvious. But looking at the car.ini of a few cars, including the traffic tank truck, I don't seem to see anything related to vehicle length/width/height.
At this point I'm guessing that the geometry of the collider is taken into account for AI behavior. The car's dimensions are what Kunos recommends for starting point of values in "car.ini" for
Code:
INERTIA=2.718,2.393,10.52                ; car polar inertia. Calculated from the car dimensions. Just enter the generic width,height,
But I don't think that entering big values there is what determines the width of the road needed for AI to pass correctly. Another possible place for dimensions values is "colliders.ini". On the tank truck I entered corresponding values in both places. Didn't test if making them smaller would affect the AI's behavior. Maybe will try that out to clarify it. Anyway that tank truck needs some attention as it tends to drive 0.5 m to the left of where it should be. But I corrected also the colliders and physics on the Isuzu Giga and Mule which are moving correctly and are surprisingly agile on the hillclimbs.

If you're curious to try them - link is in the attached txt
 

Attachments

  • trucks.txt
    109 bytes · Views: 103
Last edited:
test if making them smaller would affect the AI's behavior. Maybe will try that out to clarify it.
What I discovered confirmed that AI acts according the dimensions and position of the collider mesh. The smaller collider results in less erratic behavior when AI forms a queue. The necessary road width is dictated by "track" in "suspensions.ini" + tyres width from "tyres.ini".

But another thing also became evident - when "car.ini" has values that determine inertia box with higher volume than that of the collider the said vehicle starts to glitch like the case described by @RN4 So there is no easy solution for fixing the cars in the "no-colliders" traffic pack other than adding the relevant collider and editing "car.ini" for inertia box - smaller than collider dimensions.
 
Last edited:
...
But another thing also became evident - when "car.ini" has values that determine inertia box with higher volume than that of the collider the said vehicle starts to glitch like the case described by @RN4 So there is no easy solution for fixing the cars in the "no-colliders" traffic pack other than adding the relevant collider and editing "car.ini" for inertia box - smaller than collider dimensions.
It's really surprising that "inertia" has impact on the amount of space AI wants to keep. This means if a car has unusually high rotational inertia and the correct values are used, the AI would have erratic behavior.

The car pipeline PDF doesn't even include the word "inertia". Am I looking at the wrong documentation? The formula to convert one inertia box to actual rotational inertia numbers must be documented somewhere.
 
Last edited:
The formula to convert one inertia box to actual rotational inertia numbers must be documented somewhere.
It was a topic in some old discussion and no one could quote a source for such formula. Generally inertia is used to modify the car's behavior in turns depending of engine's position. Mid- and rear-engine cars should have the third value smaller than the car's length but nothing other than going "by feel" was recommended and nothing other than the remark in some of the Kunos' car.ini files is provided.
The infamous Arch had this to say about it in the v0.6 of his documentation
“INERTIA” determines the SPRUNG inertia of the car in the form of a dimension box that has mass specified by TOTALMASS. Unsprung mass generates its own inertia separately. You must NOT input in the total car box dimensions. A solver to solve for sprung inertia from total car inertia has been developed and may be shared in the future. Input is in meters. Typical values are smaller than the physical constraints of the vehicle.
Example: BMW E30 1.450,1.260,4.200 total, 1.179,1.339,4.149 sprung."
The car pipeline document is oriented on making the 3d model for the cars. The physics is not really a topic there
. If you like to go deep - see this resource.
It's really surprising that "inertia" has impact on the amount of space AI wants to keep. This means if a car has unusually high rotational inertia and the correct values are used, the AI would have erratic behavior.
The edited long trucks and the "Orion" bus do have a tendency to bump constantly into each other when are close in a queue.
 
Last edited:
Made a new tool which calculates speed and throttle/brake channels in an AI line. The game will use this information to colourise accelerate/brake/coast sections of the racing line display (Ctrl+I). The data is based on a fairly primitive simulation of racing behavior and won't match the actual vehicle the player is driving. But it's still better than having a brown line, especially when you're playing a completely new track with no memory of each corner.

Power/grip/drag/downforce of the simulated car can be changed at the beginning of the script.

AI files generated by acai_csv_to_line.py have no data in those channels, this tool would fix it. If an AI file was recorded while driving slowly and the accelerate/brake sections don't make sense, this tool is also helpful.
 

Attachments

  • acai_calc_speed.py.txt
    7.9 KB · Views: 74
The game will use this information to colourise accelerate/brake/coast sections of the racing line display (Ctrl+I).
Not only that but more importantly the new AI flood needs that data to spawn the cars at speed. That script fixed my problem with the 50 km loop generated on Bella Vista and I'm thankful for your new input on the topic!
 
Last edited:
I tried making Ai lines for a new map, but i have the problem that the ai wont drive on the line & stops if i get behind them. I think this has something to do with the red lines not beeing correct.... Anyone know how to fix this? It worked fine on other maps so i am a little frustrated :(
 

Attachments

  • ai line.JPG
    ai line.JPG
    235.5 KB · Views: 46
  • ai lines 2.JPG
    ai lines 2.JPG
    245.7 KB · Views: 63
I tried making Ai lines for a new map, but i have the problem that the ai wont drive on the line & stops if i get behind them. I think this has something to do with the red lines not beeing correct.... Anyone know how to fix this? It worked fine on other maps so i am a little frustrated :(
I can't recognize the track from the pics but if you are making the line that uses the right lane in all of the length I can recommend the script for generating the clean side lines in parallel to the fast_lane. If you can't understand how to use the script - send me PM with a link to the "fast_lane.ai" in a zip archive and I 'll make the lines for you.
 
In the above the lines
Code:
        # Write track-specific modifications here.
        if nomPos > 0.0905 and nomPos < 0.1572:
            rightValue = 4.5
        if nomPos > 0.1584 and nomPos < 0.1751:
            rightValue = 4.5
        if nomPos > 0.2532 and nomPos < 0.2974:
            rightValue = 4.5
        if nomPos > 0.2978 and nomPos < 0.3366:
            rightValue = 4.5
are what determines which parts of the length should have the 4.5 m space to the right. Using that .py is much like the cameras script and with the values on default like the above it makes 1.5 m borders everywhere but the defined exceptions. When you need to take measurements of the lines on track I recommend using the "AI Lines Helper" app that reads them quick and correctly.
how to use this part of the script for another spline/track?
 

Latest News

Online or Offline racing?

  • 100% online racing

    Votes: 73 7.3%
  • 75% online 25% offline

    Votes: 102 10.3%
  • 50% online 50% offline

    Votes: 145 14.6%
  • 25% online 75% offline

    Votes: 272 27.4%
  • 100% offline racing

    Votes: 398 40.0%
  • Something else, explain in comment

    Votes: 4 0.4%
Back
Top