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.

Simple Traffic System

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

  1. combatsheep

    combatsheep

    Joined:
    Jan 30, 2015
    Posts:
    129
    Hi Stephen_O,

    I'm building a transportation system for the town with STS.
    STS is great!:)

    I have a few of questions.
    When I put a traffic light at the cross road, the first car will stop but the following cars will collide to the its front car(car accident).
    Is there anything I should pay attention to the setting?

    The settings related to the current car are as follows.
    Scene_CarAccident.jpg Scene_TrafficLight.jpg setting_AITrafficControllers.jpg setting_STS_AICars.jpg


    Also, Burst 1.3.3 has been released. Is it better to update from 1.2.3 for better performance?

    Thanks.

    Env:
    STS ver 1.0.13
    Unity2019.2.10f1
    macOS 10.14.6
    Burst 1.2.3
     
    Stephen_O likes this.
  2. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,505
    The cars should stop for each other by default, if they are not, it sounds like it could be to the detection sensor not detecting the car it hit. Try checking the detection sensor layer mask on AITrafficController and make sure the car that got hit is using one of those layers.

    Also, using new versions of Burst should be ok, I have not verified it myself yet though - if there's ever an error due to API change just go back to previous version (in that case STS would be updated to match the latest versions API).
     
    combatsheep likes this.
  3. combatsheep

    combatsheep

    Joined:
    Jan 30, 2015
    Posts:
    129
    Hi Stephen_O,

    Thank you!

    I fixed it.

    The detection was fine.
    While I was checking the detection setting, I noticed the Front Sensor Length and adjusted it.

    I set the Front Sensor Length to 30 and set the Speed Limit of waypoints before the intersection to 10, 20, and 25 late.
    As a result, the following cars came to stop correctly.;)
     
    Stephen_O likes this.
  4. antimonyyq

    antimonyyq

    Joined:
    Feb 3, 2020
    Posts:
    1
    Hi Stephen_O,

    I have been trying out the yield trigger. It works great when I turned off pooling. However when I turn on both the use yield trigger and use pooling on the AI Traffic Controller, there would be an error at the following:

    NullReferenceException: Object reference not set to an instance of an object.
    TurnTheGameOn.SimpleTrafficSystem.AITrafficController.FixedUpdate () (at Assets/TurnTheGameOn/SimpleTrafficSystem/Scripts/AITrafficController.cs:229)
     
  5. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,505
    Hello,

    I'll take a look, try to reproduce this bug and follow up with my findings. I initially tested with pooling disabled, there may be something I missed, if so I'll make an update to resolve.
     
  6. frangagn

    frangagn

    Joined:
    Sep 20, 2018
    Posts:
    47
    Hi Steven,

    I'm looking at STS for a city racing game I'm building. I have a few questions:

    - At an intersection, must all cars in a lane follow the same route? For e.g. must all cars turn left or continue through, or could you setup a 25% turn left and 75% continue or other ratio?

    - Could you setup some special routes for special vehicules, city busses or taxis for e.g. that frequently stop on the side of the road?

    - Could you setup AI for pursuit, like a cop pursuing your main vehicule, or other vehicules trying to pass you?

    - Is the signal lights and brakes lights for the cars something that can be triggered by the STS? Or must each asset use its own logic for it? (for e.g. when a car must stop or turn right or left at a light, how does the asset know which lights to turn on?)

    - Does STS operate solely with traffic lights at intersections, or could you also use 4 stops intersections?

    If the asset does not do it yet, well above are some ideas to enhance it!

    Thank you!

    FG
     
    Last edited: Jul 2, 2020
    Stephen_O likes this.
  7. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,505
    You can resolve this error by changing AITrafficController line 229 from

    Code (CSharp):
    1. if (currentWaypointList[i].onReachWaypointSettings.nextPointInRoute != null)
    to

    Code (CSharp):
    1. if (currentWaypointList[i] != null)
    I'll submit an update for this soon.
     
    antimonyyq likes this.
  8. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,505
    Hello, thanks for the questions, it's always nice to hear how others would like to use the system and gain feedback.


    If multiple new route points are assigned to intersections (or any waypoint), the car will randomly choose one of the new routes.

    Yes, you can create multiple waypoint routes that are only connected to each other (taxi ropute for example), this route would never connect to the default traffic route so can be self contained with special rules.


    No, this is not supported.


    There are currently no turn signals. Brake lights are enabled via emission using the material assigned to the car controllers

    I don't have a defined workflow for stop signs, but I have recently added YieldTrigges that can help add more design options.

     
  9. frangagn

    frangagn

    Joined:
    Sep 20, 2018
    Posts:
    47
    Would the cars in the same routes connectec to each others bump into each others when the taxi stops on the side? Or would they wait for it to be done?

    Is there any way for the car to know when it's at the light whether it's going to go forward or turn? Then we can program it in the car gameobject?

    Stop signs would be a really nice add-on!

    I have two more questions:

    1. From what I understand, we can use any car asset from any other asset in the store or our own, right?

    2. Could you use STS to control pedestrian traffic on sidewalks?

    Thanks a lot! Sound that your asset is really cool.

    Francois
     
    Stephen_O likes this.
  10. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,505
    1. Yes, but I recommend cars with a dedicated emissive brake material, that way it can be assigned and used by the system - or else you'll have to fallback to using a point light shich is less optimized.

    2. Sorry, no pedestrian control.
     
  11. frangagn

    frangagn

    Joined:
    Sep 20, 2018
    Posts:
    47
    Thanks a lot Stephen, will give it a try!
     
    Stephen_O likes this.
  12. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,505
    Version 1.0.14 submitted.

    • Added brake mesh reference to AI cars to get brake material from.
    • Added brake material index to set the index the brake material uses in the mesh reference.
    • Fixed a bug where brake lights would stop working when using RandomMaterial script while using pooling.
    • Fixed a bug where yield triggers would cause errors while using pooling.
    • Fixed a bug that required a brake material to be assigned to AI cars for brake material emission. The system now generates an an unassigned default material to avoid introducing additional null checking logic overhead.
     
  13. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,505
    Version 1.0.14 is now available.
     
  14. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,505
    Last edited: Sep 20, 2020
    shyamarama and combatsheep like this.
  15. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,505
    Version 1.0.15 submitted.

    • Added Integration package with pre-configured AI traffic prefabs from Stylized Vehicle Pack (Requires Stylized Vehicles Pack).
    • Added option to populate AITrafficWaypointRoute SpawnVehicles randomly from traffic pool list if not using pooling at scene start.
     
  16. MikeUpchat

    MikeUpchat

    Joined:
    Sep 24, 2010
    Posts:
    1,049
    Quick question, how many waypoint objects do you have in your demo scene? And if for some reason a road had to be tweaked I am guessing I would have to tweak all the way points and junctions etc using that road?
     
  17. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,505
    There are 1857 waypoints from 74 waypoint routes in the demo scene. It's likely if you that if you make changes in road design you'll need to move your waypoints too.
     
  18. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,505
    Version 1.0.15 is now available.
     
    combatsheep likes this.
  19. SorraTheOrc

    SorraTheOrc

    Joined:
    Jun 11, 2016
    Posts:
    137
    Just bought STS after "almost buying it" for some time. Sales do that to me ;-)

    Installed and run the demo scene and I see pretty awful jerkiness. The profiler shows some massive periodic spikes:

    upload_2020-7-21_22-46-6.png

    While most activity spikes the main culprit is scripts:

    upload_2020-7-21_22-47-42.png

    As can be seen in the FPS this is a pretty major spike, dropping to < 30FPS. Again, this is the out of the box experience running on a very beefy I9 with 32Gb. 2019.4.f1, Burst 1.2.3. .Net 4 support enabled.

    Given the focus on performance I can't imagine this is the intended behaviour, is this a bug a config problem on my end?
     

    Attached Files:

  20. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,505
    I've shared some performance info in this post: https://forum.unity.com/threads/simple-traffic-system.794268/page-4#post-5921297

    I do see your spikes compared to what I get, do you happen to have the scene and game view both open at same time, that can be the only reason I can think of for a decrease in performance?
     
  21. SorraTheOrc

    SorraTheOrc

    Joined:
    Jun 11, 2016
    Posts:
    137
    I assume you mean "I do NOT see your spikes" ;-)

    You are correct in your guess. I just tried the same scene without the scene view and it is buttery smooth. Might be worth noting this in the README when you next update. It was a very disappointing first impression. Should have been obvious to me to try that but, well you know, users never think it's their fault!

    In that same vein, I'm trying to get yield colliders to work for me. I'm not sure if this is because I'm using them in an undocumented way (in which case this is a feature request) or because they don't work as I expect (in which case I'll provide more info on how I have it set up). I am trying to create a yield junction in which people drive like they do in the UK, that is in the absence of lights the major road has right of way and side roads must yield (Give Way to us Brits).

    I also want to use yield triggers to prevent cars turning right/left across oncoming traffic.

    I can't seem to make this work. Before I go into more detail let me ask is whether I should expect yield colliders to work without traffic lights, your tutorial uses lights so maybe this is a feature that is not implemented (in which case please consider this a feature request).

    While at it, another feature request for the yield colliders. In the US equivalent of these UK maneuvers would be a 4 way stop in which cars would always stop at the intersection and yield to any car that was there first. Would love to be able to do that too.
     
    Stephen_O likes this.
  22. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,505
    I'm working on a new user manual, I can add some notes about editor overhead performance insights, one of them being scene view.

    The yield triggers are currently only able to be used in the traffic light example I provided. I appreciate your feedback and requests in this regard; I'm often thinking of ways to improve the asset, so it's nice to hear what users would like to do, this is very useful for future update considerations..
     
    combatsheep likes this.
  23. arie1994

    arie1994

    Joined:
    Jun 30, 2016
    Posts:
    85
    Is the AI navigation completely random ?
    Would be nice to have the ability for the AI to actually navigate the rout network with A* to a given target.
    Also my vehicles have multiple convex colliders ( hood, doors , windows ,detachable parts).
    Of course this creates a bottleneck in my traffic sys.
    How all of this colliders and meshes would effect simple traffic system
     
    Last edited: Jul 25, 2020
  24. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,505
    Yes the driving pattern is random, I mat work toward a path finding solution in the future but that's not currently being worked on.

    From a performance perspective, the more sub-objects, materials, colliders, etc that are a part of the traffic car prefab, the more expensive it is to process. This is not a limitation of STS, but rather the way Unity works so it will still cause a bottleneck. Building a custom LOD system to manage your objects is really the only way to avoid a performance bottleneck.
     
  25. combatsheep

    combatsheep

    Joined:
    Jan 30, 2015
    Posts:
    129
    Hi.

    Is there an API that can remove or spawn all cars at runtime again?
    In the game, I want to remove all NPC cars or add buttons to make them appear.

    Thanks.
     
    Stephen_O likes this.
  26. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,505
    Hi,

    Yes, you can disable all by calling

    Code (CSharp):
    1. TurnTheGameOn.SimpleTrafficSystem.AITrafficController.Instance.usePooling = false;
    2. TurnTheGameOn.SimpleTrafficSystem.AITrafficController.Instance.MoveAllCarsToPool();
    then re-enable by calling

    Code (CSharp):
    1. TurnTheGameOn.SimpleTrafficSystem.AITrafficController.Instance.usePooling = true;

    It's a little primitive in that it will follow the runtime spawn rules, only re-spawning where allowed, rather than how startup spawns anywhere (ex: in front of the camera).

    I'll write an API guide soon, and also work toward adding-to and improving what's available to call. Let me know if you're in need of the startup spawn function when you turn them back on.
     
    combatsheep likes this.
  27. combatsheep

    combatsheep

    Joined:
    Jan 30, 2015
    Posts:
    129
    Hi, Stephen_O.
    Thank you!

    I tried it, but I got the following error and warning.
    [Exception] UnassignedReferenceException: The variable headLight of AITrafficCar has not been assigned.
    AITrafficController.FixedUpdate() at AITrafficController.cs

    [Warning] Can not play a disabled audio source
    EngineSound.OnEnable() at EngineSound.cs


    It seems that the headlight can be avoided by attaching a dummy GameObject, but can the warning be turned off?

    Or is it possible to erase on the spot like SetActive(false)?

    Thanks.
     
    Stephen_O likes this.
  28. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,505
    Hmm, I'm unsure why you're getting that warning, but you can edit the EngineSound script, change line 25 from
    Code (CSharp):
    1. _audioSource.Play();
    to
    Code (CSharp):
    1. if (_audioSource.enabled) _audioSource.Play();
    This should prevent the script from trying to play the disabled AudioSource.

    What I'm unsure about is why the AudioSource is disabled. I might need to make an adjustment to that script for this scenario.
     
  29. combatsheep

    combatsheep

    Joined:
    Jan 30, 2015
    Posts:
    129
    Hi, Stephen_O.

    I'm really sorry.
    I forgot that I used the culling asset for STS NPC car.
    When it culls the AudioSource from STS NPC, AI Traffic Controller has lost sight of AudioSource.

    I was able to fix the issue with your source modification instructions.:)
    No warnings appear any more.

    Thanks a lot!
     
    Stephen_O likes this.
  30. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,505
    Great, and no worries, I'm glad you've got it sorted out. :)
     
    combatsheep likes this.
  31. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,505
    A new online user manual is being created, most of the current manual has already been added, here's the link:

    https://simpletrafficsystem.turnthegameon.com/

    The API section is being worked on next. Some current sections will also have more information added. The help icon of all primary components will be updated in the next version to link to the component's API page.
     
    combatsheep and kns1966 like this.
  32. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,505
    Version 1.0.16 has been submitted.

    Online Manual (WIP) : https://simpletrafficsystem.turnthegameon.com/

    • Changed default prefab value: AITrafficController MaxSteerAngle from 37 to 42
    • Changed default prefab value: AITrafficController SteerSensitivity from 0.02 to 0.04
    • Created online user manual
    • Added HelpURLAttribute to primary components for inspector links to API documentation pages in user manual
    • Renamed script: AITrafficWaypointRouteCreator to SplineRouteCreator
    • Renamed prefab: AITrafficWaypointRouteCreator to SplineRouteCreator
    • Added Simple Traffic System category to Edit/Preferences window
    • Moved all AITrafficDebug properties to Edit/Preferences window
    • Moved all debug and gizmo properties from AITrafficPool to Edit/Preferences window
    • Moved all pooling properties from AITrafficPool to AITrafficController
    • Removed AITrafficPool scriptable object since it's now obsolete
    • Removed AITrafficDebug scriptable object since it's now obsolete
    • Improved waypoint route gizmos

     
    combatsheep likes this.
  33. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,505
    1.0.16 is now available.
     
  34. mthawley

    mthawley

    Joined:
    Sep 7, 2018
    Posts:
    100
    Hi. I have upgraded to version 1.0.16 and have restarted Unity. Now whenever I try to build the game I am getting multiple errors such as;

    Assets\TurnTheGameOn\SimpleTrafficSystem\Scripts\AITrafficController.cs(1054,108): error CS0103: The name 'STSPrefs' does not exist in the current context

    Assets\TurnTheGameOn\SimpleTrafficSystem\Scripts\AITrafficWaypointRoute.cs(168,43): error CS0103: The name 'STSPrefs' does not exist in the current context

    Assets\TurnTheGameOn\SimpleTrafficSystem\Scripts\AITrafficController.cs(233,21): error CS0103: The name 'STSPrefs' does not exist in the current context


    I am using Unity 2019.4.7

    Could you please advise?

    Cheers,
    Mark
     
    Stephen_O likes this.
  35. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,505
    Hi Mark,

    I apologize for this oversight. I'll make a fix now and submit an update.

    Since it's Friday, the update may not be available until early next week. If you or anyone else needs the fix sooner, please email me.

    stephen@turnthegameon.com

    Thank you,
    Stephen
     
    combatsheep and mthawley like this.
  36. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,505
    Version 1.0.17 has been submitted.

    • Fix a build compilation error caused by STSPrefs.
     
  37. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,505
    Version 1.0.17 is now available.
     
    combatsheep likes this.
  38. combatsheep

    combatsheep

    Joined:
    Jan 30, 2015
    Posts:
    129
    Hi.

    Is it possible to group cars and display or pool them?

    For example, I want to use it as follows.
    When the player is in town, group A cars in town are displayed and group B cars outside town are pooled.
    When a player goes out of town, it will pool the cars of group A inside the town and show the cars of group B outside the town.

    Thanks.
     
    Stephen_O likes this.
  39. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,505
    Not currently..

    But, I think one possible new feature idea might be to 'tag' cars and routes, so you can define which cars spawn to which routes during pooling updates and initial spawning. This would also allow me to have cars of specific types ignore some route path options (example a truck can only connect to routes with matching route tags when there are options to choose multiple paths).

    I'm curious to hear what you think about this as a solution, or if anyone would find this useful.

    I still have in my plans, improving runtime API for completely controlling the pool, so you could extend the system to do what you inquired about on your own. Improving API will be a focus after 1.0.18 is released, which is the version where I complete the documentation for everything that's currently available.
     
    combatsheep likes this.
  40. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,505
    Version 1.0.18 has been submitted.

    Most, if not all of the new manual is now updated and complete.

    • Improved AITrafficController inspector layout.
    • Renamed AITrafficController enableLaneChanging variable to useLaneChanging.
    • Renamed AITrafficCarOnReachWaypointInfo struct to AITrafficWaypointSettings.
    • Removed unused AITrafficLight.DisableAllLights method.
    • Removed ReoradbleList from AITrafficWaypointRoute inspector GUI.
    • Added variable tooltip descriptions to inspector for AITrafficCar, AITrafficController, AITrafficLight, AITrafficLightManager, AITrafficWaypoint, AITrafficWaypointRoute, AITrafficWaypointRouteInfo, SplineRouteCreator.
     
    combatsheep likes this.
  41. combatsheep

    combatsheep

    Joined:
    Jan 30, 2015
    Posts:
    129
    Hi Stephen_O.

    That idea is amazing!:)
    I think it would be useful if there was a function to run the route associated with the tag.
    For example, route buses and garbage trucks run on the same route, so moving the car adds reality.

    It would be great if tags could solve the features I asked.
    Currently, I am creating a city using STS in a world of 1000 unit squares with an iOS and Android application, so I think that this will be an invincible traffic asset.;)
     
    Stephen_O likes this.
  42. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,505
    I will add this feature in version 1.0.19.

    The example you provided with bus/garbage routes was also inquired about a few months back, but I was still building the editor tools (and needed to do more-complete documentation); now that those are finished, I can start looking into new usability features like this.

    In my personal project, I'm still on something like version 1.0.3, so have not thought too much about what I'll be needing that's not here yet. I'm looking forward to finishing world building, upgrading my project, and setting up traffic there; my world is 8000 square units, I'm sure this feature will be used by me as well. Questions and requests are very helpful, that said, thanks for the question on the topic as it led me to a new feature ;)
     
    combatsheep likes this.
  43. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,505
    1.0.18 is now available.
     
    combatsheep likes this.
  44. MADUXX_INC

    MADUXX_INC

    Joined:
    Apr 8, 2015
    Posts:
    5
    Great stuff, Stephen. I think the only major thing missing is a yield to stop signs feature, would this be implemented anytime soon?
     
    Stephen_O likes this.
  45. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,505
    Thank you.

    Yes, I agree, and the stop sign feature is on my radar (it's also been requested a number times). It might be the next feature added with version 1.0.20.
     
  46. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,505
    Version 1.0.19 has been submitted.

    • Added support for vehicle types; vehicles will only spawn, and merge(change lane) onto routes with matching vehicle types.

     
    combatsheep likes this.
  47. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,505
    Version 1.0.19 is now available.
     
    combatsheep likes this.
  48. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,505
    Version 1.0.20 has been submitted.

    • Added support for stop cycle system to allow a stop-sign type of behaviour at intersections where cars will take turns based on the configured sequence.
    • Added Stop Connector Configure Mode to STS Tools window.
    • Added AITrafficStopManager as a Spawn option in the STS Tools window.

     
    combatsheep likes this.
  49. mathewsbabu

    mathewsbabu

    Joined:
    Sep 30, 2014
    Posts:
    33
    Hi @Stephen_0,
    what about the compatibility with mobile devices,IOS and Android
     
  50. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,505
    Hi Mathews,

    I just saw and responded to your email.

    Yes, the asset does work on mobile, though you may not be able to have 300 cars like on the PC demo. The amount of cars you can have will be based on the processing power of the mobile cpu.