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:
script for another spline/track?
Well, you need to take note of the coordinates for the start and end of each section of the road where you want the wider side line. That's what I meant with "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."
From your question I have a sense that you don't have much experience with AI line editing and editing of AC in general. That is not a breaker but it makes the explanations more difficult for me.

For example on another track if the section of road is between "0.0000" and "0.2200" and you want the line on the left side to envelop the lane to the left you need
Code:
Code:
        # Write track-specific modifications here.
        if nomPos > 0.0000 and nomPos < 0.2200:
            leftValue = 4.5
 
Well, you need to take note of the coordinates for the start and end of each section of the road where you want the wider side line. That's what I meant with "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."
From your question I have a sense that you don't have much experience with AI line editing and editing of AC in general. That is not a breaker but it makes the explanations more difficult for me.

For example on another track if the section of road is between "0.0000" and "0.2200" and you want the line on the left side to envelop the lane to the left you need
Code:
Code:
        # Write track-specific modifications here.
        if nomPos > 0.0000 and nomPos < 0.2200:
            leftValue = 4.5
1669143153044.png

Maybe the question was asked incorrectly. I can't run a script for my spline with specific bounds and i get an error. I can apply the same border width for the entire spline.
 
Code:
        # Write track-specific modifications here.
        if nomPos > 0.0000 and nomPos < 0.2200:
            leftValue = 4.5
sorry i am also very new to this... i could not get this to work. My borders are always same distance. i wanted the border to change to 4.5m from 0.021 to 0.256 (coordinates from drs app) but somehow this did not apply. All i did was changing the nomPos > 0.0000 and nomPos < 0.2200 like you have shown above. Setting borders without changes worked fine for me so far thank you very much for all the help & information :inlove:
 
Last edited:
Break up the loops at the U-turn area and connect them with U-turns.
View attachment 500201

That confuses me. What is the reason for makin u-turns on a circuit (at least for me it looks like a circuit)? Do i have to make these or could i just let the line connected.

Also Iam interested in, how a junction spline would look like. My map has a lot of sideroads which connect main roads... Do i have to make a spline for each road and overlap the splines that traffic would join the new ones (kinda like pit lane to fast lane)? Anyone could show a picture of a "4 road" junction?
 
What is the reason for makin u-turns on a circuit
Here's what I wrote to a guy recently in PM
"When you activate the "AI" app in game it shows the loaded fast_lane (purple) and two side lines (red). The pit lane (cyan) is used only for guiding the AI in the pits. If you see more than one purple line in some place it means a single loop is made that way, not that there is more than one loop from different ai files. To make it work that way you have to plan the route very carefully to avoid overlapping the line in same lane on any part of the course. That's what I did and it's the reason some part of the SRP map stays unused by AI.
With respect of the previous regarding the one and only loop at least 2 U-turns are obviously unavoidable on touge maps (A to B). On circle maps it seems not so obvious but if you want to have the other half of the road with oncoming AI you must have the 2 U-turns.
On SRP traffic there are more than 2 U-turns"

"Break up the loops at the U-turn area and connect them with U-turns." Sim_Misg means editing the line with Blender in such way that you end up with a final single line made from several smaller lines. It is doable but you have to use additional steps because Blender add-on will not let you export the edited line if the number of vertices is different than the original. It means exporting the edited line as csv and converting csv to line, making the side lines and rendering the result.
I would recommend starting with something simpler. Put your effort in planning and drawing the line in the game.
;-)
 
Last edited:
If you see more than one purple line in some place it means a single loop is made that way, not that there is more than one loop from different ai files. To make it work that way you have to plan the route very carefully to avoid overlapping the line in same lane on any part of the course. That's what I did and it's the reason some part of the SRP map stays unused by AI.

I get it. Thanks so much for the fast reply!
 
Hey there, its me again...

Finally iam able to export the spline mesh to csv and then to fast_lane.ai.

First test was a small circle around the spawn-cube area.
Game starts an AI is spawning on the spawn-cubes but do not move.

* Is it not workin in singleplayer TrackDay Mode? Only on server?
* Does the pit surface has to be involved in any way?
* Does it matter where the spawn-cubes are placed?

Cause the cars didn't moved, i thought i need to draw the spline through the Start/Finish line. Then i made a bigger 2way line with the u turns but far away from the spawn cubes and the game crashes while loading... Any advice would be appreciated!

:EDIT:

Just to be sure - are normals essential? does it need to be a curve?
I do not know what the first vertex is and how to see or set it in blender...
 

Attachments

  • AI_Crash_Game.jpg
    AI_Crash_Game.jpg
    172.3 KB · Views: 40
  • TEST_SPLINE.csv.txt
    345.6 KB · Views: 40
Last edited:
Finally iam able to export the spline mesh to csv and then to fast_lane.ai.
First thing unclear is - how you made the spline mesh? It has to be unbroken and all vertices in correct order linearly after the first. It may be closed as a loop or not. In any occasion converting the mesh line to a curve and again to mesh helps with vertices order.
Second - converting the csv to "fast_lane.ai" with the script is not all that is needed for a working file. That "fast_lane.ai" needs generating the side lines and after that - loading and saving in ksEditor.

Third:
i thought i need to draw the spline through the Start/Finish line
Presence of start gate objects is not necessary for the AI to work. The spline in "fast_lane.ai" has to follow the road ~0.5 m above the physics surface. When you use the "ai" app in the game to draw the line app records consecutive vertices between the positions of the car's center-of-gravity and spaced exactly at the legth of the wheelbase in the direction of travel.

* Is it not workin in singleplayer TrackDay Mode? Only on server?
* Does the pit surface has to be involved in any way?
* Does it matter where the spawn-cubes are placed?
In offline mode "Track day" always needs "pit_lane.ai" that guides the AI out from the spawn area. If the spawns are some distance away from the line you need "pit_lane.ai" that guides the AI out from the spawn area to join the fast_lane.

I do not know what the first vertex is and how to see or set it in blender...
Right after loading of "fast_lane.ai" (of ***.csv) in Blender use "Tab" to enter "Edit mode" and then "." on the NumPad to center the view on the first vertice.

The attached "TEST_SPLINE.csv" is not representing a line mesh. You can see it with "Import" in Blender. Although it is a loop and there is a first vertice the result is not usable because it doesn't follow the road. You need to generate a proper line first.
 
THX so much for the help... At first i have to say, i found a fault in my csv file. there was 4 coordinates. now i export the line with [ skip PoT, save only x,y,z ] and get a similar csv file like yours. But i wonder if the order x, Z, y is messed up... ?!?!? now i imported the old spline.csv and see the horrible mess up :D the new one looks much better.

"." on NumPad i don't have. (between 0 and enter is "," but don't work)
The spline i took from my road mesh.
The road actually has several meshes which i joined together for creating the spline.
All Vertices are merged. Maybe messed up the order, cause one part of road mesh, the array started from west to east, others maybe from east to west (and north south etc.)
So i definitly should convert to curve and back to mesh...

With <ctrl> + <R> i divided the mesh 3 times and took the vertices between middle and outta lines and lifted them up (maybe not high enough if i think twice about it / depending on the weird scale i use... i will double check it.)

What is meant with LINEAR? hopefully not the distance between vertice?!?!? omg
depending on the different arrays i made, the distance is different, too.

I see, i have a lot of mistakes in there. i give it a new try tomorrow.
 

Attachments

  • NEW_SPLINE.csv.txt
    255.7 KB · Views: 41
i wonder if the order x, Z, y is messed up
Orientation of the model looks ok. Using the measure tool on your new csv I see a loop that has ~65 m in diameter. I suspect your track is ~6500 m in diameter and there is a scaling issue when you are importing the original mesh. If it is coming from 3DSimED3 fbx you always need to set "Transform"-"Scale"-"100" in Blender. On the attached csv I corrected with "Resize" in "Edit mode" and 100 on all 3 axes. That way the distance between the two parallel splines now is ~4.2 m (was 0.042 m). The first variant of the line I rendered in ksEditor I attach below and it could be usable. It has the first vertice in the original place (no conversion to curve and no spacing edit of vertices).

If the simple first example is not working sorting of vertices can be done when exporting the csv (place a check on "sort by converting to curve"). Spacing the vertices equally is easily doable with "Loop tools" add-on > "Space". In such case the first vertice changes position.
It is always important to notice the starting direction when the script runs. "Start direction: 97.3" means roughly along +X and after the position change of first vertice it will cause the spline to direct AI as left-lane (which I assume is not your intention). I corrected that too and rendered a second variant that has conversion to curve and spacing edit of vertices, right-lane direction, no overtaking. It should work.

After converting to .ai always import that .ai and check if the side lines are correctly made. In my case I always have to additionally run the separate script for setting the sides.

In any case you need to make pit_lane from the parking in the center of the map to guide the AI to the loop. Do that before placing the "fast_lane.ai" in the "ai" folder and don't forget to remove the .candidate from the "pit_lane.ai" name. Position of the start gate and first vertice don't affect the pit lane and it will function as long as it reaches from the spawns to the racing line.

If neither of the .ai works that couldn't be a problem with normals direction. I have an .ai that has normals looking exactly like that and it's working.
 

Attachments

  • first vertice changed.jpg
    first vertice changed.jpg
    362.6 KB · Views: 43
  • 1 fast_lane.7z.txt
    275.8 KB · Views: 38
  • 2 fast_lane.7z.txt
    334.3 KB · Views: 61
took the vertices between middle and outta lines and lifted them up (maybe not high enough if i think twice about it / depending on the weird scale i use... i will double check it.)
In addition to the above I meant to say - check the .ai line for positioning by importing one of the smaller segments of the road in the same Blender instance (watch out for the scale) and select the "fast_lane" object, use "Tab" to enter "Edit mode", "a" to select all vertices and then use the "Move" to adjust the offset from the road on +Z to ~0.5 m. When ready use "Tab" to toggle to "Object mode" and export the .ai.
The vertical offset is important for "AI flood" because that is the height at which the AI gets respawned.
 

Attachments

  • move.jpg
    move.jpg
    240.8 KB · Views: 42
struct.error: unpack requires a buffer of 8 bytes

The script for setting borders was working for me all the time but now i get this error... anyone know a fix maybe?
Something wrong with the raw line? If not too time-consuming try to generate the initial fast_lane.ai again. Or try a small one on the same track and see if this same error pops up in the workflow with the small fast_lane.ai.
In my experience the script for the side lines refuses to work after I've done some resizing to fast_lane.ai in Blender so I always do the side lines before resizing and then do the rest.
 
Something wrong with the raw line? If not too time-consuming try to generate the initial fast_lane.ai again. Or try a small one on the same track and see if this same error pops up in the workflow with the small fast_lane.ai.
In my experience the script for the side lines refuses to work after I've done some resizing to fast_lane.ai in Blender so I always do the side lines before resizing and then do the rest.
thank you for the reply! I could actually fix it with chatgpt xD Did some adjustements, got new errors codes, but in the end its now working again.
 

Latest News

Are you buying car setups?

  • Yes

  • No


Results are only viewable after voting.
Back
Top