• Dear visitors,

    The email issue has been finally solved.
    Thank you for your patience and happy browsing.

    Team ACM.

QUESTION Creating Working Traffic Lights for a free roam Assetto Corsa Track

2cam86

New Member
Hey there!

I'm in the very early stages of creating a free roam city map/track and I'm planning the implementation of working traffic lights. As far as I'm aware, there are two possible approaches:
  1. Through conditions (see https://github.com/ac-custom-shaders-patch/acc-extension-config/blob/master/config/tracks/common/conditions.ini)
  2. Through animating the light meshes.
Option 1 seems to be the more reasonable approach. This involves using one of the conditions and its values to resemble the signal cycle of their real life counterparts. But it seems to be very tailored to street lights among other emissive sources like building facade lighting.

Option 2 seems to be a bolder and questionable approach. This involves me animating each light mesh within their Traffic light modules to "move into the traffic light housing" when turned off, and then reveal itself when turned on; again, according to the signal cycle of their real life counterparts.

Both approaches I feel are very hacked together (albeit, as with most things). The main concern for Option 2 is how much animation Assetto Corsa can handle. I can simplify each light down to just a triangle, and a rough ChatGPT estimate suggests 1,911 individual lights, which would mean 5,733 animated triangles/light-meshes, so who knows, it might crash, it might not, but I'd love to hear your thoughts.

I also don't see any way of integrating these light cycles with mods like CSP traffic tool, so that's another concern.

All in all, I'd like to get an idea of how to best approach this project, any pointers to resources or anything that may be of interest is also greatly appreciated.

Thank you for your generosity :)
 

Xuacu

Member
Hey there!

I'm in the very early stages of creating a free roam city map/track and I'm planning the implementation of working traffic lights. As far as I'm aware, there are two possible approaches:
  1. Through conditions (see https://github.com/ac-custom-shaders-patch/acc-extension-config/blob/master/config/tracks/common/conditions.ini)
  2. Through animating the light meshes.
Option 1 seems to be the more reasonable approach. This involves using one of the conditions and its values to resemble the signal cycle of their real life counterparts. But it seems to be very tailored to street lights among other emissive sources like building facade lighting.

Option 2 seems to be a bolder and questionable approach. This involves me animating each light mesh within their Traffic light modules to "move into the traffic light housing" when turned off, and then reveal itself when turned on; again, according to the signal cycle of their real life counterparts.

Both approaches I feel are very hacked together (albeit, as with most things). The main concern for Option 2 is how much animation Assetto Corsa can handle. I can simplify each light down to just a triangle, and a rough ChatGPT estimate suggests 1,911 individual lights, which would mean 5,733 animated triangles/light-meshes, so who knows, it might crash, it might not, but I'd love to hear your thoughts.

I also don't see any way of integrating these light cycles with mods like CSP traffic tool, so that's another concern.

All in all, I'd like to get an idea of how to best approach this project, any pointers to resources or anything that may be of interest is also greatly appreciated.

Thank you for your generosity :)
Hello. I am at the same point with the intention of create some functional traffic lights so that them also work with the traffic planner.

I thought it would be as simple as editing an object by telling it when to turn on and off on a timeline, but I see that it is not that simple.

I thought that using Condition "Blink" it would be possible, but I see that it is not possible. On the other hand, thanks to the link that you shared on Github, there is a condition 70 to turn on depending on the temporary time, but it only has one time slot:

[CONDITION_70]
; active at 17:30–07:00
NAME=NIGHT_FLICK
INPUT=TIME
...
It occurred to me that I could vary that time and even make different on and off conditions for one of the lights, but I think this is programmed in a .LUT or .LUA and I have no idea how to modify those scripts.

I don't see it very clearly about animating the lights and it would be very difficult to edit them later to synchronize the signals.

Have you achieved any results, have you solved the problem? It would be appreciated if you managed to do it or if someone knows how to do it.

All the best

Xuacu

My traffic light modeling process:

 
Last edited:

Xuacu

Member
Isn't it realistic for the red light to last forever? :lol:

Sorry I cannot help, I did not used the script for this.
Yes this is the problem that I have (explained in the other post) the calculations of the on/off lights are correct but the en of the loop looks like it goes on for a long time before starting again, I don't know why happend.

I have managed to get closer to real time but the calculations have been by trial and error and I do not think it is the most correct solution
 

JoeK

New Member
You are further than I am - I have not gotten to creating my traffic lights yet. However...

If working out the programming logic - there should be 1 central timer that governs the whole AC session. Can that be queried?

If so, then a simple formula can be derived that queries the current time in the Assetto Corsa timing clock (time elapsed) and the adds a variable to cycle the light changes. GREEN 3 minutes, ORANGE - 5 seconds, RED 3 minutes (or less). That would look like...

1 - Query current time
2 - Turn GREEN
3 - End of GREEN = Current time + 3 minutes (probably in seconds)
4 - If current time = End of GREEN - turn ORANGE
5 - End of ORANGE = Current time + 5 Seconds
6 - If Current time = End of ORANGE, turn RED
7 - END of RED = Current time + 3 minutes (probably in seconds)
8 - If current time = End of RED - turn GREEN
9 - Repeat Loop 3-9

Then have each traffic light execute its own timing loop. Then you can sequence the traffic lights to time light changes for a specific driving speed - like in real municipal light timing scenarios.

There is a LUA tutorial on YouTube.
 

Xuacu

Member
You are further than I am - I have not gotten to creating my traffic lights yet. However...

If working out the programming logic - there should be 1 central timer that governs the whole AC session. Can that be queried?

If so, then a simple formula can be derived that queries the current time in the Assetto Corsa timing clock (time elapsed) and the adds a variable to cycle the light changes. GREEN 3 minutes, ORANGE - 5 seconds, RED 3 minutes (or less). That would look like...

1 - Query current time
2 - Turn GREEN
3 - End of GREEN = Current time + 3 minutes (probably in seconds)
4 - If current time = End of GREEN - turn ORANGE
5 - End of ORANGE = Current time + 5 Seconds
6 - If Current time = End of ORANGE, turn RED
7 - END of RED = Current time + 3 minutes (probably in seconds)
8 - If current time = End of RED - turn GREEN
9 - Repeat Loop 3-9

Then have each traffic light execute its own timing loop. Then you can sequence the traffic lights to time light changes for a specific driving speed - like in real municipal light timing scenarios.

There is a LUA tutorial on YouTube.

Hi! I decided to try asking chat GPT how to make a functional traffic light and it described a logical programming code to me. It also talked about LUA files but I have no idea about programming, although I would be interested in seeing that tutorial you mentioned about LUA.

I suppose that traffic planner will work with logical code, but I already told you that I am not a programmer, at the moment it eludes me, I dedicate myself more to the visual and artistic issue.
 

JoeK

New Member
Here's a link to a short course... I find this instructor to be pretty good.

"Steve's Teacher" also has a much more indepth course on LUA, with a video on each part of the language and how it use it. You can find that on his YouTube channel as well - just a bit more buried.

Programming is not difficult, it's the 'code' words and what they do/how to use them that needs a bit of practice. I equate programming to teaching a 5-6 year old simple steps to accomplish a certain task.
 

2cam86

New Member
Here's a link to a short course... I find this instructor to be pretty good.

"Steve's Teacher" also has a much more indepth course on LUA, with a video on each part of the language and how it use it. You can find that on his YouTube channel as well - just a bit more buried.

Programming is not difficult, it's the 'code' words and what they do/how to use them that needs a bit of practice. I equate programming to teaching a 5-6 year old simple steps to accomplish a certain task.
Stellar Stuff! Would def check it out
 

John Finker

New Member
Hi! I decided to try asking chat GPT how to make a functional traffic light and it described a logical programming code to me. It also talked about LUA files but I have no idea about programming, although I would be interested in seeing that tutorial you mentioned about LUA.

I suppose that traffic planner will work with logical code, but I already told you that I am not a programmer, at the moment it eludes me, I dedicate myself more to the visual and artistic issue.
Hey there,

I saw your post about using ChatGPT for programming and just had to chime in. I've been using ChatGPT-4 and it’s been a real lifesaver for me. For example, I was stuck on a tricky bug in my code related to asynchronous processing. I asked ChatGPT for help, and it not only pointed out the mistake but also explained how to handle async functions more effectively. It really boosted my productivity and understanding.

On a slightly different note, I also use ChatGPT in my everyday life. As a young woman who's into racing, I asked it for advice on racing simulators. Among the suggestions, it highlighted DOFReality, which I tried and ended up really liking. It's been great for enhancing my racing experience.

Just wanted to share my experience—AI tools like ChatGPT can be incredibly versatile and helpful!
 

Mods_team

New Member
Here's a link to a short course... I find this instructor to be pretty good.

"Steve's Teacher" also has a much more indepth course on LUA, with a video on each part of the language and how it use it. You can find that on his YouTube channel as well - just a bit more buried.

Programming is not difficult, it's the 'code' words and what they do/how to use them that needs a bit of practice. I equate programming to teaching a 5-6 year old simple steps to accomplish a certain task.
Hi, why LUA and not Python??

I am trying to programming different faults with python and I will need to create traffic lights as well.
 

Johnr777

Moderator
Hi, why LUA and not Python??

I am trying to programming different faults with python and I will need to create traffic lights as well.
LUA can access more game information, can be part of a track or car mod, etc...
Python only good for apps?
 

Mods_team

New Member
LUA can access more game information, can be part of a track or car mod, etc...
Python only good for apps?
Thanks John. Could you give me examples where it is better to program in LUA, and others where it is better to program in Python? It is being difficult to program the driver's faults in my urban maps in python. And if I add to this problem that I have to include aspects such as vehicle lights, an AI system for vehicles to follow defined routes, traffic lights... It's going to be crazy. At least it would be nice to know if there is a github that can help me or videos.
 

Johnr777

Moderator
Thanks John. Could you give me examples where it is better to program in LUA, and others where it is better to program in Python? It is being difficult to program the driver's faults in my urban maps in python. And if I add to this problem that I have to include aspects such as vehicle lights, an AI system for vehicles to follow defined routes, traffic lights... It's going to be crazy. At least it would be nice to know if there is a github that can help me or videos.
Python cant do that, again, probably only useful for APPS

Use LUA for your environment... Theres an SDK included in CSP: \assettocorsa\extension\internal\lua-sdk with the libraries needed.

And for urban traffic and lights, theres a traffic tool in CSP you can use that will give you a lot of what you need already.
 

Mods_team

New Member
Python cant do that, again, probably only useful for APPS

Use LUA for your environment... Theres an SDK included in CSP: \assettocorsa\extension\internal\lua-sdk with the libraries needed.

And for urban traffic and lights, theres a traffic tool in CSP you can use that will give you a lot of what you need already.
Thanks, I'm going to check it.
 
Top