Search Unity

  1. Get the latest news, tutorials and offers directly to your inbox with our newsletters. Sign up now.
    Dismiss Notice

Simple Traffic System

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

  1. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,449
    Simple Traffic System allows for quick creation of waypoint based routes that can be interconnected in a modular way to create traffic routes on roads in your scenes. The primary logic is highly optimized using the new C# Job System and Burst Compiler for multi-threading, allowing you to use more of your performance budget for other content.

    AI traffic logic is handled by a single AI Traffic Controller that AI Traffic Cars register to. This is a data oriented logic structure and allows the AI logic to run in parallel jobs spread across all available cores to reduce cpu usage on the main thread.

    Detailed tutorial videos are available to help teach proper workflow and demonstrate available features.

    Asset Store

    User Manual

    New support for CiDy 2 allow 1 click traffic system generation on CiDy roads.












    Key Features

    - No DLLs: Full source provided!

    - Modular: create, connect, and edit waypoint routes for AI cars to follow.

    - Waypoint Based: each waypoint can set speed limit, call stop driving, be a junction to new route point(s), or trigger custom events via Unity inspector.

    - Traffic Lights: control when AI cars can exit waypoint routes.

    - Yield Triggers: control when AI cars can proceed to next waypoint at intersections with traffic lights.

    - Traffic Stops: control when AI cars can exit waypoint routes.

    - Pooling System: disables cars far away from the player, and spawn cars around the player; allows scaling up scene size without using more cars.

    - Unity Physics Components: AI cars use Rigidbody and Wheel Colliders.

    - Unity Physics Components: AI cars use Rigidbody and Wheel Colliders.

    - Vehicle Types: define which cars can spawn/merge onto which routes.

    - Volume Sensors: more accurate detection compared to raycasts; uses layer mask to determine which objects should be detected.




    Editor Utility Tools

    - Supports Undo/Redo

    - STS Tools Window: select from various tools to help automate waypoint route configuration tasks, reducing the need to dig through the hierarchy to configure references and settings.

    - Lane Connector: draws handles in the scene view over end of route waypoints, select 2 routes to auto configure lane change points.

    - Route Connector: draws handles in the scene view over route waypoints to create route connections between waypoints.

    - Route Editor: view/edit all waypoints from the selected route.

    - Signal Connector: draws handles in the scene view over end of route waypoints and traffic lights. Used to connect/disconnect route traffic signal lights.

    - Spawn Points: draws handles in the scene view over waypoints to manually add/remove spawn points, randomly assign spawn points to all waypoints, or remove spawn points from all waypoints.

    - Spline Route Creator: procedurally generates multiple waypoint routes and their waypoints along a spline with a unique offset for each, allowing you to quickly create routes and waypoints on large roads with curves or inclines.

    - Stop Connector: draws handles in the scene view over end of route waypoints and traffic stops. Used to connect/disconnect route traffic stops.

    - Yield Triggers: draws handles in the scene view over route waypoints, and yield triggers. Used to connect/disconnect waypoints and yield triggers.




    Project Requirements

    • Player Settings (Edit -> Project Settings -> Player)
    - API Compatibility Level .Net 4.x

    • Package Manager Dependencies (auto installed on import)
    - Burst 1.4.1
    - Collections 0.1.1

    • To use the burst compiler in standalone builds, install the Windows SDK and VC++ toolkit from the Visual Studio Installer.
     
    Last edited: Apr 18, 2021
  2. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,449
    The package has been submitted to the asset store and is currently pending review.
     
  3. Freznosis

    Freznosis

    Joined:
    Jul 16, 2014
    Posts:
    293
    Looking good man. :)
     
    Stephen_O likes this.
  4. dibdab

    dibdab

    Joined:
    Jul 5, 2011
    Posts:
    976
    looks like it has branching routes, too. I think you missed to mention them
    white and yellow car here
    intersect.jpg
    red and green car here
    intersect2.jpg
     
  5. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,449
    Yes, route endpoints can have multiple connections to new routes, if more than 1 connection is assigned in the new route point array the new route is chosen randomly.
     
    dibdab likes this.
  6. jhon143

    jhon143

    Joined:
    Sep 26, 2019
    Posts:
    3
    Stephen what is the project name at unity store for search???
     
  7. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,449
    The package is still pending review, I'll post here when Unity approves it.
     
  8. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,449
  9. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,449
    Version 1.0.1 submitted.

    • Added a 'Reverse Waypoints' function to the AITrafficWaypointRoute; this is useful to reduce configuration time when setting up multiple parallel lanes for opposite direction.

    ReverseWaypoints.gif

    ReverseWaypoints_.gif
     
    Last edited: Jan 3, 2020
    marcell123455 and Antypodish like this.
  10. egem2015

    egem2015

    Joined:
    Oct 27, 2015
    Posts:
    73
    Hi Sephen

    it is great packages. good sales.

    I have 2 question

    1) This asset is included
    Arcade Racer: Racing Game Development Kit
    asset?

    2) if it is not included is there a discount for who has arcade racer?

    thanks in advance.

    King regards.
     
  11. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    8,637
    That are completely unrelated assets, made by different devs.

    If is not included in the description, simply don't assume it is there.
     
    Last edited: Jan 3, 2020
    Stephen_O likes this.
  12. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,449
    AR:RGDK is mine, but it's unrelated to STS so there's no discount. AR:RGDK does include a traffic system, if you haven't seen the tutorials are here and here; the best place to ask about these would be in the AR:RGDK thread.

    STS is a more optimized traffic system using only the required logic and variables with C# Jobs and Burst Compiler for a more simple and lightweight implementation.
     
    Antypodish likes this.
  13. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    8,637
    Ah it is indeed. Sorry. I looked before, and I had some vision blur I think :)
    I thought I have seen other name/icon.
     
    Stephen_O likes this.
  14. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,449
    It's all good, no worries :)
     
  15. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,449
    I got tired of digging through all the waypoint routes and their points to manually connect routes, so I made an editor window that will load all routes from scene and provide handles in scene view to help make these connections.

    RouteConnector_Window.gif
     
    Last edited: Jan 8, 2020
    JBR-games likes this.
  16. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,449
    Version 1.0.2 submitted.

    • Added 'Tools > Simple Traffic System > Route Connector Window'. This draws handles in the scene view over route waypoints used to create route connections between waypoints without needing to manually select the gameobjects.

     
    Freznosis likes this.
  17. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,449
    I built a spline based tool to manage configuring multiple routes and waypoints for adjacent lanes much faster and efficient. Since it's spline based, it works well for curved roads and inclines.

    This helps automates much of the layout process to reduce the amount of work required to configure traffic lanes.

    Route Creator.gif
     
    marcell123455 and Antypodish like this.
  18. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,449
    Version 1.0.3 submitted.

    • Added spine based 'Route Creator' to create multiple AITrafficWaypointRoutes and generate their waypoints along a spline with offset for each. This allows for fast creation of routs and points and helps reduce the amount of work required compared to manually creating each route and waypoint on the routes.

     
  19. Freznosis

    Freznosis

    Joined:
    Jul 16, 2014
    Posts:
    293
    Might I suggest some asset integration scripts? Might help get more buyers for your asset.

    I'm pretty sure EasyRoads and RoadArchitect provided spline points, so you can automatically get them all and place the lanes. I believe the newest 3.3 beta of EasyRoads even has full AI lane data.
     
    Stephen_O likes this.
  20. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,449
    Thanks for the suggestion, maybe I'll check it out.
     
  21. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,449
    I setup a new Signal Connector window to assign traffic lights via scene view. Much easier than using a manual workflow. Also useful to debug/visualize what a light is connected to.

    SignalConnectorWindow.gif
     
    Colin_MacLeod and JBR-games like this.
  22. jcpruett1298

    jcpruett1298

    Joined:
    Oct 27, 2018
    Posts:
    3
    looking good and so far a great purchase. is there a way to make it so the traffic lights can be on the corner across from the intersection? i wanted to make a role play type driving game and wanted my lights to look more realistic rather than being directly over my cars. Thanks in advance for a reply and great work!
     
    Stephen_O likes this.
  23. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,449
    Thanks.

    The traffic lights are just small meshes that get enabled/disabled, you can place them anywhere you like. What I do is add them to a traffic light model prefab and position them to overlay the model's signal lights.
     
    jcpruett1298 likes this.
  24. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,449
    Version 1.0.4 submitted.

    • Added Signal Connector Window. This draws handles in the scene view over end of route waypoints and traffic lights. Used for visual debug and assign the route to the signal light.

     
    JBR-games likes this.
  25. jcpruett1298

    jcpruett1298

    Joined:
    Oct 27, 2018
    Posts:
    3
    what needs to be edited so the traffic stops and detects the player? I have a scene set up however the traffic just plows right into me
     
    Freznosis and JBR-games like this.
  26. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,449
    You can set the Detection Sensor Layer Mask to the layers you want it to detect. I recommend creating a new layer, something like Vehicles and make sure the car collider objects are set to this layer.

    DetectionSensorlayermask.png
     
    JBR-games, Freznosis and jcpruett1298 like this.
  27. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,449
    As many of you may know, I've built this traffic system for use in my own personal project. Much of the functionality in this asset comes from a performance or workflow need.

    First the asset was written to use the job system and be performance friendly, next I needed to setup my roads to use it and created all the helper tools I've recently added to make it quick and easy.

    Now that I have it running in my open world, I wanted to take it a step further and add traffic pooling functionality. Since my project's open world is so big, it takes a lot of cars to fill up the streets. So to keep the amount of cars in the scene being processed from scaling up with world size, I setup a traffic pooling solution. This allows the cars to only be active in a radius around the player.

    The pooling shown here was done inside of my project and needs to be ported out to Simple Traffic System, I'll work on getting it together for next update.

     
    v_Jay_v, Freznosis and JBR-games like this.
  28. localhost

    localhost

    Joined:
    Dec 9, 2012
    Posts:
    38
    Hi!,

    Lovely asset. Do you have a timeframe on when you would be releasing the pooling system as a update?
    Keen on purchasing.

    Kind Regards
     
    Stephen_O likes this.
  29. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,449
    I'll likely have it submitted before bed tonight, should be approved and on the store early next week.
     
  30. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,449
    1.0.5 will be submitted later today. I need to do some minor cleanup, documentation, and submit.

    • Added support for traffic pooling.
    • Added traffic pooling demo scene.
    • Moved all Jobs to their own script files in a jobs directory.
    • Moved most Structs to their own script files in a structs directory.
    • Removed MaterialManager, it was unnecessary and could be confusing since it was only responsible for assigning demo car materials.
    • Added AITrafficCarRandomMaterial component used for default demo scene to apply a random material to demo car prefab (replaces Material Manager).
    • Added more AITrafficCar prefabs for color variance used with pooling demo.

    I uploaded a new WebGL demo, it has the default demo scene, and a button to load the pooling demo scene: https://www.turnthegameon.com/simple-traffic-system
     
    JBR-games likes this.
  31. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,449
    JBR-games likes this.
  32. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,449
    Getting ready to submit in the next few minutes, here's the video overview.

     
  33. Freznosis

    Freznosis

    Joined:
    Jul 16, 2014
    Posts:
    293
    Your progress on this asset is awesome! Glad I bought it. I wouldn't be surprised if you increased the price after the pooling update.

    What are your plans for the future?
     
    Stephen_O likes this.
  34. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,449
    Thanks, I'd like to let some more people get in at the lower price before raising it. I might increase the price a bit in February.

    I'm hoping to get some more feedback, as well as continue building my game with it as a real-world development test case, most of the features added after launch came from a workflow or usage need that I discovered while using the asset. Doing this allows me to get a better feel of what's working or not to determine if something needs to change.

    At some point I'd like to consolidate the editor window tools into a single interface, but I don't plan on doing that now, I'd prefer to do more testing to make sure it works the way it needs to. So far I'm happy with the results, just need to keep testing to make sure foundation is solid and it's easy to use.
     
    Freznosis and JBR-games like this.
  35. jcpruett1298

    jcpruett1298

    Joined:
    Oct 27, 2018
    Posts:
    3
    How do I get my cars to slow down at corners? I’ve attempted to adjust the speed limit and it works for one car or so but the rest just come speeding through without slowing a bit
     
  36. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,449
    The speed limit is tied directly to each waypoint. Every car on the path that reaches each waypoint will have it's speed limit updated to the waypoint's speed limit.

    WaypointSpeedLimit.png

    I've found that 90 degree right turns need to go around 7 mph for my game, I usually step the speed limit down incrementally from default speed for the waypoints leading up to that turn so the car doesn't break too abruptly.
     
    Freznosis, jcpruett1298 and JBR-games like this.
  37. AlexJaeger

    AlexJaeger

    Joined:
    Oct 8, 2014
    Posts:
    2
    Hi,

    I saw you tested WebGL, have you tried the Mobile Platforms? Or if you havent, is there anything that sticks out that would prevent mobile?
     
  38. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,449
    I haven't personally tested on mobile yet, but one of the other users left a review and said it works well on mobile.
     
  39. raziel786

    raziel786

    Joined:
    May 6, 2014
    Posts:
    22
    Hi,

    I am very interested in the product. I currently have a vehicle rigged via Realistic Car Controller. If I crash into one of the traffic vehicles, is it possible for the vehicle to stop or have some form of interaction?
     
    Stephen_O likes this.
  40. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,449
    The cars are physics based but use drag to help slow and stop them, so there are some artificial forces helping to keep them in place. If you crash into a traffic car, it will move around up to a meter or 2 depending on how hard or where it was hit.
     
  41. icave2

    icave2

    Joined:
    Mar 30, 2018
    Posts:
    3
    Hi,
    I'm looking for a traffic system for Unity and Simple Traffic System looks very interesting. I have two questions:
    - is it possible to have cars traveling at a different speed on the same road (e.g. could we define different classes of cars with different max speed?)
    - is it possible to implement passing the obstacle (e.g. stopped another car)?
     
  42. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,449
    No, I plan to add lane changing in the future but not sure when I'll get to adding it.

    - No, this this will be added when lane changing is added.

    If these features are important to you, it might be better to wait until the features are available to purchase.
     
  43. Colin_MacLeod

    Colin_MacLeod

    Joined:
    Feb 11, 2014
    Posts:
    173
    @Stephen_O Bought the asset yesterday - having tried to implement something similar myself over the last many months, I do think it's absolutely incredible what you have done.

    The asset appears to be extremely well put together and represents incredible value for money. Thank you for sharing this - it is exactly what my project needed.

    I did notice a couple of UI/Editor things that may be specific to Unity 2019.3.x - don't know. I emailed you about the first - my waypoints don't seem to go all the way to the end point when using route creator.

    The other thing I'm finding tricky is holding Alt (Mac Option) to place points. The thing is, Command-Option together seems to be standard Unity for click to pan, at least on a Mac. When I have a Simple Traffic System object selected, I can't overcome this muscle memory and end up creating a bunch of unwanted extra points.

    I couldn't see how to get rid of the extra ones (probably on me – I'm still just getting to grips with the tool), so for now deleting the whole thing and starting over. Any tips how to correct would be appreciated!

    Could you use a modifier other than Alt/Option, something that doesn't clash with Unity pan? Other assets have a toggle somewhere on the inspector, for example.

    Am very much looking forward to using your asset tons over the coming weeks. It is a beautiful thing. Lane changing sounds great, and I'm looking forward to seeing where you take it.
     
    Stephen_O likes this.
  44. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,449
    Thanks for the detailed feedback, it's a lot of useful information.

    The asset was written in about a month or 2, but I've been iterating on the logic used for about 2 years in my spare time and used it as a starting point. After learning about the new job system, I realized I could do some cool stuff using it by moving away from the monobehaviour based design. Once that was setup it became more clear that I can build up helper tools to improve workflow; now we're here at the current version.

    This is a bug, I sent you an email with a fix for the waypoints, that will be included in 1.0.6 along with support for lane changing.

    To delete a point, select the Waypoint list element in the AITrafficWaypointRoute inspector and press the - button at the bottom of the list to remove it from the list, then delete that point from the scene. I'll eventually clean this up a bit so you only need to press - button.

    I'll setup an inspector field somewhere with options to change the keys used for spawn point functions. For now you can manually edit a couple lines to change which keys are used. Feel free to send me an email on this topic if you have questions.

    Line 107 of Editor_AITrafficWaypointRoute used for insert points
    Change e.alt and e.control
    Code (CSharp):
    1. if (e.type == EventType.MouseDown && e.button == 0 && e.alt && e.button == 0 && e.control)
    Line 116 Editor_AITrafficWaypointRoute used for add points
    Change e.alt
    Code (CSharp):
    1. else if (e.type == EventType.MouseDown && e.button == 0 && e.alt)
     
    Last edited: Feb 9, 2020
  45. Colin_MacLeod

    Colin_MacLeod

    Joined:
    Feb 11, 2014
    Posts:
    173
    @Stephen_O

    Hey, thanks for this fast turnaround.

    Applied the fix just now and, yes indeed, that really does the trick.

    Thanks too for the pointer to change keyboard mapping. Will give that a go shortly.

    So far, I've been experimenting with a simple circuit road layout with 3 cars spawned in either direction. It took me approximately zero time to set this up which was really impressive.

    It was working fine but then I pulled Opsive Third Person Controller into the scene and that broke it. Fault appears to be layer related. Opsive sets up a number of layers when you install it and this seems to clash.

    The symptoms are that the cars spawn but do not move. If I delete the Opsive character from the scene (or even the Opsive Layer Manager from the character), they are fine again when I start again.

    Appreciate this is a vague description – I'm just starting to dig into the actual cause – but does that ring any bells at all or do you have any pointers?
     
    Last edited: Feb 10, 2020
  46. Colin_MacLeod

    Colin_MacLeod

    Joined:
    Feb 11, 2014
    Posts:
    173
    I got traffic moving again by simply moving the cars to a different layer. However, I have a weird thing with wheels falling from the sky on start – can't figure that one out. Will ping you a quick email.
     
  47. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,449
    I'm not sure what changes installing the opsive asset will do to a project's default project settings, knowing what they are will likely lead to the conflict and allow me to reproduce the issue on my end. My guess is opsive is also using the same layers.

    The AITrafficController default detection layers are 29, 30 and 31. I'll probably change this to a single layer.

    The AITrafficCar prefabs root is set to layer 30 by default.

    Also check to see if they've modified the project's layer collision matrix.

    Try changing the layer of AITrafficCar, and the detection layer mask on AITrafficController to layers that make sense, are not shared with opsive systems, and not disabled in the project's layer collision matrix.
     

    Attached Files:

    Colin_MacLeod likes this.
  48. Zak-Broflovsky

    Zak-Broflovsky

    Joined:
    Apr 6, 2017
    Posts:
    1
    Do you plan to overtake another vehicle when it is slower?
    A turn light signal (blinker) to indicate a change of direction?

    Thank you for your reply and anyway, great work!
     
    Stephen_O likes this.
  49. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,449
    I'm working on lane changing to overtake slower cars now, I still have a few bugs to work out but it's close to being ready.
     
  50. Hazneliel

    Hazneliel

    Joined:
    Nov 14, 2013
    Posts:
    242
    Hello, do you have any plans of adding urban people walking?
     
unityunity