Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice
Dismiss Notice
Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.

Simple Traffic System

Discussion in 'Assets and Asset Store' started by Stephen_O, Dec 15, 2019.

  1. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    508
  2. marcell123455

    marcell123455

    Joined:
    Jun 18, 2014
    Posts:
    257
    I created a solution to setup waypoint routes automatically with easyroads. Check out the TurnTheGameOn discord server where I posted my solution. ;)

    https://discord.gg/U4DURYkQ
     
    Stephen_O likes this.
  3. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,500
    Very cool, a number of users requested this, I'm sure they will find it useful!
     
    marcell123455 likes this.
  4. thelocationlabdeveloper

    thelocationlabdeveloper

    Joined:
    Sep 8, 2020
    Posts:
    14
    I have rigged my tram/train object according to STS and its moving fine. But the problem is it is not turning well. I mean all the boggies are turning at once. Is there any way available to rig the tram properly with multiple bogies/Wagons?
     
  5. MorpheusXI

    MorpheusXI

    Joined:
    Jan 18, 2018
    Posts:
    65
    Hi the Discord Invite has expired, any chance adding to documentation? I may but your asset soon...
     
    Vaupell likes this.
  6. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,500
    Here's a link that won't expire: https://discord.gg/HP65H5C
     
  7. daniel6839

    daniel6839

    Joined:
    Dec 16, 2017
    Posts:
    14
    I see that to configure pooling, the center point needs to be assigned manually in the inspector. Is there any other way to configure this? Tried to do this for the mobile racing template, but in the existing scenes, the player car and cameras spawn after the scene starts.
     
  8. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,500
    You can do some light scripting to assign that field at runtime, which is just a transform. Adding a script like this to the player car would work.

    Code (CSharp):
    1. using UnityEngine;
    2. using TurnTheGameOn.SimpleTrafficSystem;
    3.  
    4. public class AssignPoolingCenter : MonoBehaviour
    5. {
    6.     private void Awake()
    7.     {
    8.         // Find AITrafficController
    9.         AITrafficController controller = FindObjectOfType<AITrafficController>();
    10.         // Set AITrafficController.centerPoint
    11.         controller.centerPoint = transform;
    12.     }
    13. }
     
  9. combatsheep

    combatsheep

    Joined:
    Jan 30, 2015
    Posts:
    129
    Hi.

    NPC cars no longer ignore signals or become unstable.

    <SOLVED!!>
    ---------------
    If the distance between the nodes near the stop line at the signalized intersection is too narrow, the car will not stop. After widening the node spacing, the car now normally stops at a red light.
    ---------------

    ↑ This is the point ! :)

    In such a case, what are the points to be aware of when setting STS?
    All cars have the same sensors and are set normally.

    Thanks

    Unity2019.4.21f
    macOS 11.6 BigSur
    Target device :Android/iOS
     
    Last edited: Dec 25, 2021
    AGregori likes this.
  10. megapode

    megapode

    Joined:
    May 4, 2021
    Posts:
    10
    Hi, I’m trying to use the route editor to delete some waypoints in a long route but it is only showing the first 22 waypoints. Am I doing something wrong, please?
    I have over 100 points in a route as I am using STS as a ‘clever’ spline system for a demo rather than traffic :)

    many thanks
     
  11. DromoDesigner

    DromoDesigner

    Joined:
    Mar 27, 2016
    Posts:
    70

    Hello,

    I last posted here about a year ago for a project I was planning, about a game that included road building.

    Other work got in the way of development, but I now have the time to continue the project, and I have bought your asset.

    In the game players will place roads on a map, similar to city building games. The simulated population will drive cars on the newly placed roads. Originally I wanted to simulate individual cars going on journeys from point to point. However, I have decided that this is too complex for what I need, so I would just like the cars to appear as background props when the player's camera is over the road network (a bit like how cars work in Grand Theft Auto, where they spawn around the player).

    The player will make roads by placing road tiles on terrain, and I would like these new roads to be connected to the traffic network when they are placed so that cars can travel on them. In your reply to me a year ago you mentioned that you would add a method making it possible to register new routes with the AITrafficController at runtime. I am wondering if you have added this method?

    Thank you for your help.

    Have a good day.
     
  12. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,500
    Hello, version 1.0.37 received this functionality, you can check my post below to see an example:

     
    DromoDesigner likes this.
  13. DromoDesigner

    DromoDesigner

    Joined:
    Mar 27, 2016
    Posts:
    70
    Thank you for your reply - that looks like exactly what I need!
     
    Stephen_O likes this.
  14. kimtomom06

    kimtomom06

    Joined:
    Jan 31, 2018
    Posts:
    2
    Please help the car is jittering badly when moving If I reduce the fixedtimestep value, it is stable, but I don't want to reduce the value because there is a performance problem.
     
  15. KaushikKARA

    KaushikKARA

    Joined:
    Aug 5, 2021
    Posts:
    2
    Hi,
    I am trying to create the simulation for a highway. I created the lane using the spline route creator. I am trying to create the difference with the fast and the slow lanes. There a way to set minimun speed to a way point [similar to the SpeedLimit], or some work around for the same?

    Is there a way to create lane changing where the car goes from slower lane, overtakes another car and gets back to the same lane?

    I look forward to your support,
    Thanks,
    Kaushik
     
  16. AmolGame

    AmolGame

    Joined:
    Jul 6, 2021
    Posts:
    1
    can we use this package in multiplayer game using mirror networking
     
  17. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,500
    No, this asset does not include any network sync features for Mirror.
     
  18. KaushikKARA

    KaushikKARA

    Joined:
    Aug 5, 2021
    Posts:
    2
    Hi,

    - Is it possible to make sure that the left lane is always faster than the right lane?
    - Is it possible to maintain all the cars at constant speed in a particular lane?

    Thanks!
     
  19. Giannisimic

    Giannisimic

    Joined:
    Aug 18, 2017
    Posts:
    2
    Hi Stephan,

    great asset! We have one issue though - is it possible that cars, after overtaking another one, return to their start lane? That would be awesome.
     
  20. faziii

    faziii

    Joined:
    Jun 11, 2019
    Posts:
    17
    Hi! I have weird problem on route connection. The cars are colliding. Is there anyway to control it?
     
  21. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,500
    Thanks for the feedback. It looks like you're using the AITrafficCar.GoToStartOnStop option, which returns the car to the first point of the route it was spawned at.

    I can add a TeleportToPointOnTriggerEnter utility script/prefab, that you can place around your scene with a collider. This will let you set trigger areas that return cars to a specific point that you set via inspector, instead of of using the AITrafficCar.GoToStartOnStop option.

    I'll add this tonight and post here when it's ready.
     
  22. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,500
    Version 1.0.59 is now available.

    • Added utility script TeleportToWaypointOnTriggerEnter. Attach this script to a waypoint to teleport the car to the assigned waypoint.
    • Update Burst to 1.6.6

    @faziii Attaching this script to your final point will let you choose a waypoint for cars to go when they reach an unconnected waypoint. If you use this script, you should disable AITrafficCar.GoToStartOnStop option on your cars.
     
  23. faziii

    faziii

    Joined:
    Jun 11, 2019
    Posts:
    17
    Hi Stephen! Thanks for your valuable answer and work. This excellent support by you. But unfortunately this will not solve the problem. Because I want to flow the traffic continuously. If i use your solution then, i have to recheck that which point is free then respawn the car at specifc node. It is not suitable and it will also break the pooling circle. Like cars are respawning within the circle.
    My case is that i have multiple paths, where i want to show the traffic continuously and i don't want to spawn traffic near my camera. The traffic should spawn at distance like in pooling case. Now considering this situation do you have recommendation/solution? The traffic should be continuous!
     
  24. faziii

    faziii

    Joined:
    Jun 11, 2019
    Posts:
    17
    Hi! I tried your latest package but now this time cars are spawning back to back again at start pointing. Is there any intelligent way avialble to control so that first it check if the starting point has already a car then wait until his released from the starting point. Some kind of queue?
     
  25. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,500
    it sounds like you want to use the pooling system, with the ReturnToPoolOnTriggerEnter script attached to your final/unconnected waypoints. Traffic spawns up to the density you set at spawn points following the pooling system rules, specifically for you: making sure the spawn point does not contain other cars.
     
  26. hwz2017

    hwz2017

    Joined:
    May 24, 2017
    Posts:
    1
    Help! AITrafficLightManager(Inspector UI)not show corret in Unity 2021.3.4f1c1
    upload_2022-7-5_16-5-24.png
     
  27. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,500
  28. savantedroid

    savantedroid

    Joined:
    Oct 8, 2015
    Posts:
    12
    I have a suggestion for the Stop Manager. Currently giving a fixed number for wait and active is a little unrealistic. I wish the system could activate the next AITrafficStop automatically if the active one has no cars waiting for that TrafficStop.
     
  29. coooboy

    coooboy

    Joined:
    Aug 17, 2021
    Posts:
    12
    Why does my AI traffic car not stop at the red light and keep going whether I tap yield for traffic light or not?
     
  30. coooboy

    coooboy

    Joined:
    Aug 17, 2021
    Posts:
    12
    I want to make my vehicle trigger the generation of some specific traffic flow when it passes a certain trigger, but neither AITrafficcontroller nor AITrafficwaypointroute supports set active(true). I don't want the traffic flow to be automatically generated at the beginning of the game.
     
  31. coooboy

    coooboy

    Joined:
    Aug 17, 2021
    Posts:
    12
    Hi @Stephen_0, why is my ai traffic car spawned one waypoint apart instead of every waypoint. I don't have a spawn point set. The speed limit is 80 and the spacing between each waypoint is about 80-100.
    upload_2022-7-19_19-32-47.png
     
  32. coooboy

    coooboy

    Joined:
    Aug 17, 2021
    Posts:
    12
    Hi @Stephen_0, why do I set up 10 cars but only one comes out? Sorry for mentioning several questions in a row, it's just that these questions have really bothered me for a long time and I look forward to getting your answers, thank you very much.
    upload_2022-7-19_19-47-28.png
     
  33. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,500
    The yield trigger is just a box collider that is used as a detection area, when a car is in it, car's that are at waypoints that have it assigned will not proceed until it is empty. I recommend watching the tutorial video which demonstrates how to use it at an intersection.

    If you want to spawn cars manually, you can check the RegistercarRuntime script, whech is an example of how to spawn a car and register it to the AITrafficController, it's located at:
    TurnTheGameOn\SimpleTrafficSystem\Scripts\Utility\RegisterCarRuntime

    That's how default spawning is configured. You can use spawn points to control where cars will spawn if that's your goal. Also look at RegisterCarRuntime script mentioned above to spawn a specific car at a specific point.

    Your route does not have enough waypoints to hold the cars you want to spawn, That route looks like it only has 2 points, a car will no spawn at final point, so the first waypoint is the only valid spawn location.
     
  34. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,500
    Thanks for the recommendation, I will consider it for future updates.
     
  35. coooboy

    coooboy

    Joined:
    Aug 17, 2021
    Posts:
    12
    Hi @Stephen_0, whether a spawnpoint only generates one car. If there are 10 cars in WaypointRoute, but only 1 spawnpoint, can only 1 car be generated. If I want to generate all the vehicles in WaypointRoute, do I need to set the same number of spawnpoints.
     
  36. coooboy

    coooboy

    Joined:
    Aug 17, 2021
    Posts:
    12

    I wrote a Trafficmanager according to RegisterCarRuntime and then triggered the Trafficmanager traffic flow generation through a certain point trigger, but it seems that I have no way to control the traffic flow generated in the first frame when the game is running.
     
  37. kimtomom06

    kimtomom06

    Joined:
    Jan 31, 2018
    Posts:
    2
    I try to skip the car AI in the middle of Update() for optimization, the cars will all stop and then move again, which is very unsightly. Is there any way to solve this

    AI TrafficController script
    Update(){
    if(a==3){
    (Existing script)
    a=0;
    }else{
    a++;
    }
    }


    }
     
  38. faziii

    faziii

    Joined:
    Jun 11, 2019
    Posts:
    17
    We are using pooling system with spawn point and without spawn point. But the problem is sometime, one car is spawn on top of another car sometime? Cars are colliding sometime. It not detect before spawn that the place is empty or not.
     
  39. garamanx

    garamanx

    Joined:
    Apr 3, 2019
    Posts:
    10
    Just put up a street system with traffic lights, and duplicated and edited your prefab car a bit. But the cars keep colliding into traffic jams. Can you help me please?

    upload_2022-8-16_15-58-45.png

    upload_2022-8-16_15-59-32.png
     
  40. coooboy

    coooboy

    Joined:
    Aug 17, 2021
    Posts:
    12
    Hi, Stephen_O, what's the difference between the traffic prefabs of AI Traffic Controller and the spawn traffic vehicles of AI Traffic Waypoint Route. I mean which number works.
     
    Last edited: Sep 22, 2022
  41. coooboy

    coooboy

    Joined:
    Aug 17, 2021
    Posts:
    12
    Hi Stephen_O, which speed has a higher priority? AI Traffic Car Random Speed or speed limit of AI Traffic Waypoint
     
  42. coooboy

    coooboy

    Joined:
    Aug 17, 2021
    Posts:
    12
    Hi Stephen_O, very nice traffic system. I'm using the traffic system to generate traffic flow and drive my car in the flow. May I ask what causes the vehicles in front to stop suddenly
     
  43. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,500
    If you enable spawn cars from AITrafficController on the AITrafficWaypointRoutes, then AITrafficController prefabs are used instead of AITrafficWaypointRoute prefabs.

    AITrafficWaypoint will be what sets a speed limit the car will never pass, the random speed sets a random top speed between the range when the car is enabled.

    The cars sensors detect objects by layer, set in the AITrafficController LayerMask. If the car stops for an object in your scene, check it's layer, and determine if it should be changed or removed from the LayerMask. A tutorial for adjusting the LayerMask to detect a player car can be found here:

    https://simpletrafficsystem.turnthegameon.com/tutorials/video-tutorials/16.-using-a-player-car

    In general you want to configure the LayerMask to only include object layers that you want the car to stop for, all other objects in your scene should use different layers.
     
  44. coooboy

    coooboy

    Joined:
    Aug 17, 2021
    Posts:
    12


    I changed the models of AITraffic car according to your video, but the LOD and AITraffic car have different textures, resulting in the addition of brake material, which makes the whole car red. I think it's troublesome to add light. I haven't added it yet. The car can run, but it seems that the brake has become strange and cars suddenly stop. The sensors have been set on a layer. I don't know whether the light or brake material is necessary or will affect the braking. upload_2022-9-26_19-42-0.png upload_2022-9-26_19-42-30.png

    By the way, when the waypoint is below the road surface, cars' behaviors become strange, such as turning left/right suddenly and hitting the guard bar or brake suddenly. Waypoints often locate partially below the surface when there are hundreds of waypoints.


    I found the reason. my scene is a four-lane expressway scenario. The speed of newborn cars in the pooling is zero and accelerates slowly compared to following cars, so the fast following cars (speed=105km/h) will decelerate dramatically and even stop. In drivers' view, there are some kinds of traffic jams though the traffic flow speed is identical. I think there are two options to solve this problem. One is to increase the born speed of cars in pooling; another is to decrease the drag force when sensors detect front cars.
     
    Last edited: Sep 28, 2022
  45. shafei1

    shafei1

    Joined:
    Dec 8, 2021
    Posts:
    1
    Hi, could I also use the waypoint system not only to spawn AI cars but also to control part of the journey of the driver? Please let me know if this is possible
     
  46. coooboy

    coooboy

    Joined:
    Aug 17, 2021
    Posts:
    12
    Hi, I have seen your lane change logic in AITrafficController around line840-920. I have set two routes and an obstacle in one route with many lane change points, but these cars will get into a traffic jam at the emerging point.
    upload_2022-10-27_13-1-0.jpeg
     
  47. coooboy

    coooboy

    Joined:
    Aug 17, 2021
    Posts:
    12
    Hello, I meet a question about the AICars deceleration rapidly. Here is the situation: I have set many spawn points on the highway and their speed limit is 100km/h. I take my own car as the center of a pooling system. When I drive my car forward, I can see the AICars lining up. From the Scene view, I find that when I drive fast, the first car spawned in the pooling is accelerating from speed zero and every following car will decelerate dramatically, which looks weird. So, how to solve this problem? Thank you very much.