Search Unity

  1. All Pro and Enterprise subscribers: find helpful & inspiring creative, tech, and business know-how in the new Unity Success Hub. Sign in to stay up to date.
    Dismiss Notice
  2. 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,457
    Version 1.0.51 submitted

    • Added support for stop sign intersections with CiDy integration.
    • Added Regenerate Roads option to CiDy integration. It checks if roads are using the STS configured traffic light or stop sign. If not, the correct prefab will be assigned, then the road will be regenerated to spawn it.
    • Improved end of route car stop behavior, cars will now stop closer to the 2nd from last waypoint.
    • Changed AITrafficStop.waypointRoutes from array to list
    • Fixed a bug where deleting a waypoint through the route editor would not work, and cause an error if the point's new route point array had an empty element.
     
  2. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,457
    Version 1.0.52 submitted

    • Updated minimum asset version to Unity 2019.4 LTS
    • Updated Burst to 1.4.4
    • Updated Collections to 0.9.0
    • Added HDRP support and demo scenes; import demo scenes via STS Tools.
    • Added URP support and demo scenes; import demo scenes via STS Tools.
     
    Last edited: Feb 18, 2021
  3. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,457
    Version 1.0.52 is now available. Here's a new tutorial for the HDRP and URP demos:

     
    Bartolomeus755 likes this.
  4. tgentry

    tgentry

    Joined:
    Feb 11, 2013
    Posts:
    35
    This is a great system. And I enjoy using it. I use Unity for making short visualization movies. Some of the other traffic assets will cause the cars to jerk if you are trying to follow above the cars in the direction they are traveling. They work fine in game but using the Recorder trying to capture frames to convert to a movie not so great. Simple Traffic does not do that. But I have a request, how about a car rig component that will set up 3rd party cars to work in the system. I followed a video which was easy to follow and setup a car. Imported it into a traffic lane with multiple cars of the same prefab. 2 different things happened. First the car followed the paths and was spawned as expected. But the wheels would not work. The second way, as soon as I hit play, my cars appeared in the correct positions. Then all of the wheels blew off of the cars and started falling with gravity everywhere in the scene. Really funny to watch, but not the result I was trying for. Needless to say a car rigger would make my videos easier. I would even pay for it as a plug-in to this system.
     
  5. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,457
    Hello, it sounds like the car model you setup was not properly configured for STS, you should be able to use any standard car model. The wheels need to be assigned to the AITrafficCar script; it sounds like they're not assigned if they are not moving. Here's an updated car rigging tutorial that I recently made:

     
  6. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    482
    I havent been able to put a lot of look into it due to that storm that hit but I get errors if I use collections 0.9.0 unsure if anyone else had the issue but I havent been able to actually really take a look
     
  7. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,457
    Thanks for mentioning it, If you, or anyone else has issues collections with 0.9.0 please let me know. I did not get any error when testing with STS, but if it turns out collections 0.9.0 has errors for other reasons I can revert to an older version. Luckily it's close to 1.0 so hopefully will be out of preview soon, and work for everyone.
     
  8. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    482
    So I found the issue. I downgraded entities to use 0.1.1 collections and I needed to upgrade it to a version that supported 0.9.0 collections
     
    Stephen_O likes this.
  9. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,457
    Version 1.0.53 submitted.

    • Fixed a bug where AITrafficController.GetAccelerationInput was not returning the correct value.
    • Exposed AITrafficController.disabledPosition to inspector; the position that cars are sent to when being disabled.
    • Reduced default AITrafficController.steerSensitivity from .04 to .03.
     
  10. TonismoGames

    TonismoGames

    Joined:
    Jun 12, 2018
    Posts:
    70
    Hi @Stephen_O ,
    Does your asset have a feature where I can set waypoint to my modular road prefabs instead of having to redo waypoints in each new map?
     
  11. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,457
    Hello. You can add routes to prefab roads, but there's no automation for connecting the points, you would likely need to use the route connector tool as shown at 1:20 in the video below, or write a custom script that can detect nearby points from adjacent pieces to make the connections.

     
  12. Ryan-Hayle

    Ryan-Hayle

    Joined:
    Feb 16, 2014
    Posts:
    98
    Last edited: Mar 9, 2021
  13. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,457
    No, currently the only road integration I have is for CiDy.



    The developer reached out to me to create this integration; we worked together for a few weeks to define and create what would be needed for STS to generate a traffic system automatically, based on road and intersection data from his system. He did a lot of the internal calculations to define waypoint placement/connections, as well as signal placement, connections, and ordering to create usable data; this allowed me to generate all the required content by querying his data. Without having this data, it would take me much longer than a few weeks to create an integration for another developers code by creating the logic myself, so it's doubtful I will create any other road integrations unless a developer were to work with me, assisting by providing the required data.
     
    Last edited: Mar 10, 2021
  14. coldblue3434

    coldblue3434

    Joined:
    Mar 12, 2021
    Posts:
    2
    Hi Stephen,

    i need your help, firstly i added AITrafficController and AITrafficWaypointRoute to Hierarchy then added 10 waypoints to road. I select your car prefab for spawn traffic vehicles and ticked use spawn points. On spawn points windows i created spawn points. After, on AITrafficController select use pooling and added camera to center point. When i run the scene it gives error like Object reference not set an instance of an point. If i tick use pooling when scene running, i can see pooling system has working. Can you help me? I hope that i could explain my problem. Thanks for asset...
     
  15. Stephen_O

    Stephen_O

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

    I'm not sure if I understand completely, but I do understand you want to use pooling. To use pooling, the easiest setup would be:

    1. Add AITrafficController, enable pooling, assign center point
    2. Add AITrafficWaypointRoute, add waypoints, add spawn points
    3 Press play, the scene should run and spawn cars without error
     
  16. coldblue3434

    coldblue3434

    Joined:
    Mar 12, 2021
    Posts:
    2
    Thanks for answer,

    I did what you said, it gives same error.



    If i run scene without enabling pooling then enabling pooling when scene running, it is spawning cars.
     
  17. Fortunato1

    Fortunato1

    Joined:
    Jul 28, 2013
    Posts:
    17
    Hi. Please add feature to setup 6 wheeled car, or car with more then 4 wheels.
    I see in your code that you simple get 4 wheels via [] of array where first [0] and [1] is front wheels and [2], [3] is rear wheels. Probably need to use loop with conditions and maybe need bools "powered" or "steering" for wheels.
    upload_2021-3-14_22-28-23.png
     
  18. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,457
    Do you have a car assigned to the AITrafficController Traffic Prefabs? If you're using STS Tools to spawn an AITrafficController, the prefab should have one assigned by default.
     
  19. Stephen_O

    Stephen_O

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

    There's a utility script included that you can attach to the additional wheels, so they can copy rotation from back wheels:

    Assets\TurnTheGameOn\SimpleTrafficSystem\Scripts\Utility\FakeWheel
     
  20. Mike891

    Mike891

    Joined:
    May 18, 2019
    Posts:
    23
    Do you have trial available?
     
  21. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,457
    No, I don't have a trial version.
     
  22. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,457
    Version 1.0.54 submitted.
    • Fixed a bug where STSPrefs.debugProcessTime was set to true by default in builds, resulting in unnecessary logging. This value is now set to false by default.
    • Added DemoPooling_Mobile scene.
     
  23. MFKJ

    MFKJ

    Joined:
    May 13, 2015
    Posts:
    264
    Thanks for the asset. I hope you have answered this before! I have made a path with 7 points and assigned 9 cars to spawn Traffic Vehicle list but it alway instantiating 3 cars? Even after changing the max density (from 10 to 20) it remains the same. Further is there any way available to loop the traffic?
     
  24. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,457
    On the AITrafficWaypointRoute, you can enable the option 'Use Spawn Points', assign the prefabs you want to spawn to "Spawn Traffic Vehicles", and make sure there are enough Spawn Points on the route for the amount you want to spawn.
    Example.gif


    To loop the route, add the first point of the route to the last route point's NewRoutePoint list.
    LoopRoute.gif
     
  25. MFKJ

    MFKJ

    Joined:
    May 13, 2015
    Posts:
    264
    Thanks for the reply. I know the way of looping that you describe in the answer but i don't want to do it this way. I mean that car should stopped and vanish at the end point and re appear or active from the start.!
     
  26. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,457
    You can enable 'Go To Start On Stop' on the AITrafficCar script to achieve this behavior:

    GoToStartOnStop.jpg
     
  27. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,457
    Version 1.0.55 submitted.

    • Fixed a bug where modifying AITrafficCar.frontSensorSize would not resize the sensor.
     
  28. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,457
    Version 1.0.56 submitted.

    • Fixed a bug where setting STSPrefs.debugProcessTime would not be saved.
    • Fixed a bug where assigning yield triggers to a prefab object via STS Tools would not mark the object dirty, resulting in the changes not being saved properly.
    • Changed AITrafficController use of Physics.BoxCast to BoxcastCommand.
     
  29. dajnoo

    dajnoo

    Joined:
    Jun 9, 2018
    Posts:
    4
    Mirror integration would be nice :)
     
  30. Tomasko2

    Tomasko2

    Joined:
    Apr 5, 2021
    Posts:
    2
    Hi! In your post from Jan 11 you mentioned that it’s possible to turn a player car autonomous at runtime. I’m new to unity and struggling to achieve that, could you please give some pointers on how to do it?
     
    Last edited: May 5, 2021
  31. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,457
    I don't have a guide, as this requires custom scripting, and there's no user input scripts included for AI cars, however AITrafficCar.DisableAIProcessing and AITrafficCar.EnableAIProcessing can be called on AI cars to stop the AITrafficController from controlling them, diabling AI processing will allow you to have your own scripts control the car, in general this would be setting values on the wheel colliders to make the car drive.

    If you want to register a car to the AITrafficController at runtime, you can look at the RegisterCarRuntime script as an exam0ple.
     
  32. Fortunato1

    Fortunato1

    Joined:
    Jul 28, 2013
    Posts:
    17
    Bug with CiDy integration.
     
  33. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,457
    That error looks like it's from CiDy, missing a reference, the script that has an error is:
    Assets/CiDy/CiDyAssets/CiDyScripts/CiDyGraph.cs:9222

    I noticed you posted this in the CiDy discord, the CiDy dev should notice it too, and provide a fix.
     
  34. Tomasko2

    Tomasko2

    Joined:
    Apr 5, 2021
    Posts:
    2
    Thanks for the advice, I've managed to make it work! The only issue now is that my player car controller does not work when the car is registered to AITrafficController for some strange reason, even after calling AITrafficCar.DisableAIProcessing. Is there a way to deregister a car from the AITrafficController?
     
  35. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,457
    There's not a way to deregister, but I will look into this. The idea with DisableAIProcessing is that it should allow you to do whatever is needed, but it sounds like I may have broke that with a recent update. Thanks for letting me know, I'll check it out this weekend and submit a fix, will post here when it's submitted.
     
  36. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,457
    I ran a test on a car using a the standard assets car controller script, after disabling AI processing I'm able to control the car just fine.

    Perhaps what you're experiencing is that the car's rigidbody drag values are left on the last value assigned by the AI system, which may be interfering with your player controller. When you call AITrafficCar.DisableAIProcessing, make sure you set the physics values as needed on the Rigidbody and WheelColliders.
     
  37. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    482
    How did you make it work because now I'm having this issue
     
  38. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,457
    I used the unity standard assets car controller script, called AITrafficCar.DisableAIProcessing on the car with the script, enabled the script, then reduced the drag values. From there, my input allowed the car to steer and move; there wasn't anything else controlling the car components.
     
  39. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    482
    i get this error when i hit play. it pauses it and i can hit play to start it again. im using cidy along with sts.

    InvalidOperationException: The NativeArray has been deallocated, it is not allowed to access it
    Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle.CheckDeallocateAndThrow (Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle handle) (at <a5949084587241189a974c7df1839e1c>:0)
    Unity.Collections.LowLevel.Unsafe.DisposeSentinel.Dispose (Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle& safety, Unity.Collections.LowLevel.Unsafe.DisposeSentinel& sentinel) (at <a5949084587241189a974c7df1839e1c>:0)
    UnityEngine.Jobs.TransformAccessArray.Dispose () (at <a5949084587241189a974c7df1839e1c>:0)
    TurnTheGameOn.SimpleTrafficSystem.AITrafficController.DisposeArrays (System.Boolean _isQuit) (at Assets/TurnTheGameOn/SimpleTrafficSystem/Scripts/AITrafficController.cs:1266)
    TurnTheGameOn.SimpleTrafficSystem.AITrafficController.OnDestroy () (at Assets/TurnTheGameOn/SimpleTrafficSystem/Scripts/AITrafficController.cs:1191)
     
  40. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,457
    I'm not seeing any errors when I press play from after generating roads and traffic with CiDy and STS using Unity 2020.3 LTS. Can you provide reproduction steps?
     
  41. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    482
    i no longer have the issue by delaying the activation of your game objects. could i request integration with easyroads3d at some point? its my prefer road tool but having to place nodes for roads then do it again for traffic is very time consuming and i would love to have them both work together
     
    Stephen_O likes this.
  42. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,457
    I'm glad you have it working.

    Thanks for the request, at this time I'm not sure if I will add any more integrations, but it is useful to hear what users would like to see available for future considerations with updates.
     
  43. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    482
    i understand. for the most part im just using cidy because it saves a lot of time not having to do the sts steps
     
  44. daibutsu

    daibutsu

    Joined:
    Nov 28, 2017
    Posts:
    29
    Hey guys,

    We have implemented system and perfectly using it but have some performance issue.
    It is becasue AITrafficController.FixedUpdate(). It consumes 17,5% of CPU time.

    Tested both on Android and iOS. Safe.png
     
unityunity