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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Simple Traffic System

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

  1. DromoDesigner

    DromoDesigner

    Joined:
    Mar 27, 2016
    Posts:
    73

    Hi - thank you for your detailed response - I'm still working out if this solution might work for me. I hope it will, as I really like the look of it!
     
    Stephen_O likes this.
  2. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,507
    There's not currently a way. I'll add some new methods to in 1.0.38 that you can use to get sensor status in a custom logic check to evaluate if a car is stuck.

    1.0.38 example:

    Code (CSharp):
    1. using TurnTheGameOn.SimpleTrafficSystem;
    2. using UnityEngine;
    3.  
    4. public class StuckVariableCheck : MonoBehaviour
    5. {
    6.     private AITrafficCar car;
    7.     public bool leftHit, rightHit, frontHit;
    8.     public float speed;
    9.  
    10.     void Start()
    11.     {
    12.         car = GetComponent<AITrafficCar>();
    13.     }
    14.  
    15.     void Update()
    16.     {
    17.         leftHit = car.IsLeftSensor();   /// Returns true if left sensor is triggered.
    18.         rightHit = car.IsRightSensor(); /// Returns true if right sensor is triggered.
    19.         frontHit = car.IsFrontSensor(); /// Returns true if front sensor is triggered.
    20.         speed = car.CurrentSpeed();
    21.     }
    22. }
     
    amynox likes this.
  3. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,507
    Hello, the traffic cars were never tested and designed to travel at that speed, but I can provide some guidance to allow it. Typically the vehicles will not have much stability at higher speeds.

    The system uses drag to slow the cars, by default the car has a minimum drag and angular drag amount to help keep the vehicle stable, this is what's preventing you from easily reaching higher speeds. This drag is set by the AITrafficController - Car Settings, you can reduce or remove the minimum drag and minimum angular drag to allow the cars to reach higher speeds.
     
    Maturajii likes this.
  4. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,507
    That's very odd, there's something different in your project for sure, but I'm not sure where the conflict would be, this is the first time anyone has ever experienced this to my knowledge.

    The only object with a custom layer (layer 30) is the collider on the car prefabs. The layers are used on the AITrafficController - Car Settings in a Layer Mask to detect and stop for other cars. You can change the collider layer to any you like, and adjust the Detection Sensor Layer Mask to match, but I'm not sure that's the cause.

    As a long shot, can you check the Project Settings - Time and ensure the timescale is set to 1? This is the only way I can make all car stop processing.
     
  5. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,507
    Version 1.0.37 is now available.
     
  6. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,507
    Version 1.0.38 submitted.

    • Added IsLeftSensor method to AITrafficCar, returns true if right sensor is triggered.
    • Added IsRightSensor method to AITrafficCar, returns true if right sensor is triggered.
    • Added IsFrontSensor method to AITrafficCar, returns true if front sensor is triggered.
    • Updated burst to 1.4.1
     
    amynox likes this.
  7. ZolnierGames

    ZolnierGames

    Joined:
    Feb 19, 2018
    Posts:
    87
    Nice idea! You should also add a check to see how long the car has been stopped so you can send it back to the pool in case something happens, which often does....
     
  8. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,507
    I won't add this logic into the system because it requires additional processing each frame, I don't think most people will use it.

    But you can certainly add a timer while at 0 speed to the example above, then customize as you need:

    Code (CSharp):
    1. using TurnTheGameOn.SimpleTrafficSystem;
    2. using UnityEngine;
    3.  
    4. public class StuckVariableCheck : MonoBehaviour
    5. {
    6.     private AITrafficCar car;
    7.     public bool leftHit, rightHit, frontHit;
    8.     public float speed;
    9.     public float stuckTime = 60f;
    10.     private float stopTime;
    11.     private bool isStuck;
    12.  
    13.     void Start()
    14.     {
    15.         car = GetComponent<AITrafficCar>();
    16.     }
    17.  
    18.     void Update()
    19.     {
    20.         leftHit = car.IsLeftSensor();   /// Returns true if left sensor is triggered.
    21.         rightHit = car.IsRightSensor(); /// Returns true if right sensor is triggered.
    22.         frontHit = car.IsFrontSensor(); /// Returns true if front sensor is triggered.
    23.         speed = car.CurrentSpeed();
    24.         if (speed == 0)
    25.         {
    26.             stopTime += Time.deltaTime;
    27.             if (!isStuck)
    28.             {
    29.                 if (stopTime == stuckTime)
    30.                 {
    31.                     isStuck = true;
    32.                     IsStuckEvent();
    33.                 }
    34.             }
    35.         }
    36.         else
    37.         {
    38.             stopTime = 0;
    39.             if (isStuck)
    40.             {
    41.                 isStuck = false;
    42.                 IsNotStuckEvent();
    43.             }
    44.         }
    45.     }
    46.  
    47.     void IsStuckEvent()
    48.     {
    49.         /// Trigger stuck event
    50.     }
    51.  
    52.     void IsNotStuckEvent()
    53.     {
    54.         /// Trigger un stuck event
    55.     }
    56.  
    57. }
     
    amynox likes this.
  9. daibutsu

    daibutsu

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

    Thanks for this awesome asset. Would like to ask, whyi have this kind of rotated wheels.
    While i'm in prefab mode and create new car, everything looks great, but once, i go in the game but wheels looks like reversed.
    e09e27b82cc756897bd33db8e88de131 (1).jpg 0733c59e9a0fb319f7a4174236b87d38.jpg
     
  10. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,507
    Hello, check the wheel references you assigned on the AITrafficCar script, it looks like you mixed up the front wheel assignments.
     
  11. Maturajii

    Maturajii

    Joined:
    May 25, 2019
    Posts:
    2


    Thank you
    I was able to increase the speed.
    Wonderful.
     
    Stephen_O likes this.
  12. amynox

    amynox

    Joined:
    Oct 23, 2016
    Posts:
    172
    We can probably speedup this kind of checks for all the cars in the simulation with Jobs System. What do you thing?
     
  13. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,507
    I won't add it to the primary logic loop in the AITraffiCController because it will require additional processing for a minor feature request that most won't require/use. I'd like to keep the core system from being bloated with misc minor features. Instead, I prefer to have it only responsible for what it actually does, control the cars. API calls are available to build out features like this.

    From experience, the more you add to a system, the harder it is to read/modify/iterate on, instead it's best for systems to more modular where possible. That said, my approach for misc minor features like this is for them to be additional components that you can add to your cars. At that point, there's nothing stopping you from using the job system yourself to manage additional components for improved performance where necessary.
     
    amynox likes this.
  14. blaurain

    blaurain

    Joined:
    Jan 19, 2018
    Posts:
    10
    I did double check the project settings time and I again cleared out the entire project and all the meta files, restarted my machine a few times and installed it fresh the next day but still something is conflicting and all cars in all three demos scenes just sit idle with waypoints set to the same few nodes (see image below of the DemoStopSigns scene for a scaled down view of whats going on when the scene is live)
    stopsign.png

    So even without knowing exactly whats going wrong, can you tell me what would prevent the cars from setting new waypoints ahead of them and following those? It seems like its stuck at some specific initialization point
     
  15. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,507
    You did mention it does not happen in a fresh project, so something in your project is different from a default project. I've brought up all the possible causes I can think of. Like I said previously, I've never experienced this, neither has anyone else that I know of, and I don't have a way to reproduce the issue.

    Without knowing more about your project, I'm just guessing. You're welcome to email me the project, if you do please include your invoice number, I can try to take a look to see what you have going on in there.
     
  16. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,507
    Version 1.0.38 is now available.
     
  17. blaurain

    blaurain

    Joined:
    Jan 19, 2018
    Posts:
    10
    Thanks but its a huge project, I'm not sure how that would work. I'm just asking at this point if you recognize the setup process where it has not yet assigned the correct waypoints and what would prevent that code from executing (where is it located and what triggers it?) so you can point me in the right direction of debugging this thing. Otherwise I have to move on with the project and bail on this tool if I can't get it to work. Thanks again!
     
  18. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,507
    There's nothing that has ever stopped the code from executing in any tests I've run. It runs fine in a default project, I can't reproduce this, something in your project is different from default project, without knowing more, or being able to debug it myself I'm just guessing.

    Sending me a stripped down version of your project will allow me to debug what's different between your project and a default project.
     
  19. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,507
    Version 1.0.39 submitted.

    • Improved AITrafficLightManager to log a warning and disable itself if no lights are assigned.
    • Improved AITrafficController inspector, foldout menus were changed to tab menus for better visibility.
    • Added Documentation and Discussion Forum links to 'Tools > SimpleTrafficSystem' dropdown menu.
     
  20. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,507
    Version 1.0.39 is now available.
     
  21. blaurain

    blaurain

    Joined:
    Jan 19, 2018
    Posts:
    10
    OK thanks I will do that, I'm just not sure what to strip out. Everything in the code is namespaced and I am only running your demo, so in theory the rest of my project wouldn't interfere unless there is anything in the code relying on global settings. Should I try and strip the rest of the project besides your package/demo and send that over?
     
  22. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,507
    The goal would be to isolate any conflict. Best approach would be to duplicate the project, then begin stripping down content and testing as you go to try to isolate and determine if an actual asset is the conflict. It's likely an asset if you delete something and it works again. If you're able to strip down to just STS and it still doesn't work, then the conflict would be isolated to just the project. Ideally sending me just the project with STS installed where the demo scene does not work would allow me to analyze the project.
     
  23. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,507
    Version 1.0.40 submitted.

    • Added StuckTimeOut utility script to disable or move the car to the pool when stopped for a duration.
     
  24. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,507
    Version 1.0.40 is now available.
     
  25. Guacamolay

    Guacamolay

    Joined:
    Jun 24, 2013
    Posts:
    63
    Hello, I just got this asset and so far everything seems awesome and really well made (the performance in particular is incredible, so amazing work there!)

    One small issue I've been trying to figure out is with the density of the cars when pooling. I don't want very dense traffic, I'd like something quite evenly spaced and open, so I lowered the vehicle density right down to 30 to 50 (If you look at a lot of open world games the vehicles are rarely densely packed to allow players more room to drive through traffic). Right now if I set the density value to about 30, I get small dense packs of cars, followed by empty road for a long stretch, then back to another dense pack of cars. (I think I know why this might be happening - it spawns the full pool of vehicles, and then has to wait until they despawn before creating more?)

    Is there currently anyway to have the cars more evenly spread across the full stretch of the route?

    I've been thinking there might be ways to achieve this by distancing new vehicle spawns from other vehicles, or having a density value per km (I think routes have a max density, but not a minimum density?), rather than number of vehicles on screen?
     
    Last edited: Nov 30, 2020
  26. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,507
    Hello, thanks for the feedback. Currently the best way to achieve your goal would be to enable the "Use Route Limit" option, and set the "Max Density" on each AITrafficWaypointRoute. This will prevent over spawning on routes and allow you to keep a higher density so cars are available as the zones move.

    I like the idea of also setting a limit inside of the zones, I might add that as an optional toggle in the near future to provide another layer of control. I'll consider some changes in this area.
     
    Guacamolay likes this.
  27. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,507
    Version 1.0.41 submitted.

    • Updated Burst dependency to 1.4.2
    • Moved sensor size/length and minDrag/AngularDrag variables from AITrafficController to AITrafficCar. This allows car prefabs to have more unique variations in their settings.
     
    amynox likes this.
  28. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,507
    Version 1.0.41 is now available.
     
    amynox likes this.
  29. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,507
    Version 1.0.42 submitted.

    • Improved stopping at traffic light stop-position accuracy, cars will now stop closer to the 2nd from last point.
     
  30. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,507
    version 1.0.42 is now available.
     
  31. thor42168

    thor42168

    Joined:
    Sep 17, 2020
    Posts:
    2
    Hi, i just tried to use the Integration/StylizedVehiclePack, but all "brake material mesh" of Combined/Car1 .. Truck1 have 'missing prefab dummy'. Any pointers what's going on? Pressing Play complains about "Index out of bounds" at AITrafficWaypointRoute.cs:59. Using Version 1.0.42
     
    Last edited: Dec 4, 2020
  32. Stephen_O

    Stephen_O

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

    I just did a quick test using the current versions of each asset, did not get any errors, but it looks like some references became broken due to changes made in the recent Stylized Vehicle Pack update. I'll rebuild the integration, and submit it today, will be available in the v 1.0.43 update.

    Thanks for letting me know.

    If you'd like the integration fix sooner than when it's approved by Unity, please email me with STS invoice number stephen@turnthegameon.com
     
  33. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,507
    Version 1.0.43 submitted.

    • Updated StylizedVehiclePack integration to match the pack's current version.
    • Removed redundant variable AItrafficCar.weheels[].mesh
    • Removed Brake Material field from AITrafficCar inspector, this variable is auto assigned an instanced material via the mesh renderer reference.
    • Added a tab with Settings and References buttons to AITrafficCar inspector, moved inspector fields into these tabs. Improves readability.
    • Added 'Auto Rig Brake Mesh' button to AITrafficCar inspector. Searches children to find the mesh, and material index that has the matching 'Brake Light' material name, set in Preferences.
    • Added 'Auto Rig Wheel Mesh' button to AITrafficCar inspector. Searches children to find the meshes that have the matching 'Wheel' names, set in Preferences.
     
    Guacamolay and thor42168 like this.
  34. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,507
    Version 1.0.43 is now available.
     
    thor42168 likes this.
  35. chrislarabell

    chrislarabell

    Joined:
    Sep 14, 2017
    Posts:
    9
    Hi Stephen,

    I'm trying to have the best of both worlds. I would like to have the STS vehicles have a little more intelligence like Arcade Racer. When I tried to use Arcade Racer to simulate traffic, it was much better at detecting other vehicles, but I would also like the performance of STS. I'm trying to implement a traffic system that includes a highway. I have updated the drag values in STS to increase the top speed and I will eventually deal with the stability issues.

    These are the issues I am currently struggling with:

    I have the cars going in one direction in a large three lane circle for now, and the brake lights pulse like strobes and sometimes the vehicles merge into each other for different reasons. The first reason seems to be that one vehicle is in the left lane and one vehicle is in the right lane and both choose their next target to be the same center waypoint. The second reason seems to happen when the sensors of the lane changing vehicle do not detect the vehicle currently in the lane when the change to a different lane is decided. How can I remedy these items?

    Overall, I'm looking for smoother flow with the normal traffic. Logic like "If a vehicle in one lane is slower, try to merge one lane left. If unable, slow down and match speed until lane to the left is clear or I exit the multi-lane highway. If merged left, merge right when able." Is this something I can manage in the settings?

    I will eventually introduce vehicles with a little more unpredictable behavior and would like the normal traffic to try to avoid them by stopping or changing lanes.

    If the overall solution is to implement a more robust decision making ability, where would I get the data to make those decisions? Data like waypoint target and distance to the target, then how do I change the waypoint target to a different lane or route?

    Thank you in advance for the help and creating these assets!
     
  36. Stephen_O

    Stephen_O

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

    Arcade Racer AI cars have 11 BoxCast sensors, STS uses 3, there's much less data to work with using STS compared to the racer version. While Arcade Racer AI logic is good, it's a bit complex and monobehaviour based which makes it hard to scale as well as STS.

    I have to do some R&D, and create a suitable demo scene that supports highway speed simulations. I'd like to do this sooner, but will take time to start due to modeling not being my strong skill.

    I think for your scenario, you would need to implement your own sensor logic and instruct the cars based on your rules so you can correct undesired behavior. Sensor logic is located in AITrafficController lines 771-966. Front sensor logic (line 774) is where braking is triggered based on forward sensor hit distance. Side sensor logic (line 804) is where lane change logic is handled and triggered.

    AITrafficController lines 904-911 call this when conditions are met:
    AITrafficCar.ChangeToRouteWaypoint(AITrafficWaypointSettings)

    AITrafficController lines 437-535 are the native arrays/lists that contain all the variables for each car indexed, with that you can observe/search what's set where, and adjust as/if needed.

    Thanks for the feedback, it's very useful for me to hear what you're trying to use the system for, and any challenges you're facing.
     
  37. localhost

    localhost

    Joined:
    Dec 9, 2012
    Posts:
    43
    How would you go about getting the nearest waypoint and continuing on it via the api?
     
  38. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,507
    Code (CSharp):
    1. using TurnTheGameOn.SimpleTrafficSystem;
    2. using UnityEngine;
    3.  
    4. public class GetRoutePathPoints : MonoBehaviour
    5. {
    6.     public AITrafficCar car;
    7.  
    8.     void QueryCurrentPath()
    9.     {
    10.         int carIndex = car.assignedIndex; // AITrafficCar index on AITrafficController
    11.         AITrafficWaypointRoute route = AITrafficController.Instance.GetCarRoute(carIndex);
    12.         AITrafficWaypoint nextWaypoint = AITrafficController.Instance.GetCurrentWaypoint(carIndex);
    13.         int waypointIndex = nextWaypoint.onReachWaypointSettings.waypointIndexnumber - 1;
    14.         for (int i = 0; i < route.waypointDataList.Count; i++) { } // list of waypoints in route
    15.     }
    16. }
     
  39. localhost

    localhost

    Joined:
    Dec 9, 2012
    Posts:
    43
    Sorry I meant nearest waypoint closest to the AITrafficCar

    So say I clear the current waypoint and disable ai processing to do something unrelated to STS and then when I'm finished I want them to go back on the nearest route by finding the route closest to them and continuing, would that be possible?
     
  40. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,507
    You can use:

    Code (CSharp):
    1. AITrafficController.GetRoutes()
    Then loop through them to get waypoints:

    Code (CSharp):
    1. void GetClosestRoutePoint()
    2.     {
    3.         AITrafficWaypointRoute[] routes = AITrafficController.Instance.GetRoutes();
    4.         List<AITrafficWaypoint> allWaypoints = new List<AITrafficWaypoint>();
    5.         for (int i = 0; i < routes.Length; i++)
    6.         {
    7.             for (int j = 0; j < routes[i].waypointDataList.Count; j++)
    8.             {
    9.                 allWaypoints.Add(routes[i].waypointDataList[j]._waypoint);
    10.             }
    11.         }
    12.         // loop thorogh allWaypoints List with a distance check to find closest...
    13.     }
    An example of AITrafficCar.ChangeToRouteWaypoint to set a new path: https://forum.unity.com/threads/simple-traffic-system.794268/page-6#post-6299857
     
    localhost likes this.
  41. localhost

    localhost

    Joined:
    Dec 9, 2012
    Posts:
    43
    Would it be possible to have a offset of a waypoint?

    Say you have a waypoint that you use changetoroute with but add a offset so it'd be say... 1 meter to the right of the waypoint that the car would drive to.

    ITS traffic system has something similar to this.

    This could be handy for street parking/police etc
     
  42. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,507
    The drive target position is only set once, and cached when a car reaches a waypoint via AITrafficController.Instance.Set_RoutePointPositionArray(assignedIndex) from AITrafficCar.OnReachedWaypoint callback, it's optimizations like this that allow for improved performance. In order to support that feature the target position would need to be updated every frame instead of a reach waypoint callback, or have an alternative way of setting the AITrafficController.routePointPositionNL value which is what the car will drive toward and where an offset could be applied.

    I believe ITS is spline based, and is querying the spline each frame, so it's more easily able to apply an offset since the path is always known. STS in theory could do that, but it would be negating a significant performance improvement, so I chose to go the callback route.
     
  43. Rock3

    Rock3

    Joined:
    Dec 20, 2017
    Posts:
    5
    屏幕截图 2020-12-20 161646.jpg I have the same problem in the newest version! (publish for android)
     
  44. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,507
    I can't reproduce this build error on latest version. From a previous user post that resolved the issue:

     
  45. verticalshiftgame

    verticalshiftgame

    Joined:
    Jan 6, 2021
    Posts:
    1
    Hey there, I’m trying to use this system to put some cars through my city. I’m trying to have them fly through. I can get that effect by taking off the mesh renderer of the planes I’m having them drive on but I was hoping to have them be able to merge vertically as well as horizontally. I’m running into the issue of these cars needing some sort of collider under them to move on so if the cars want to merge vertically, they can go on an upward sloping plane but if I don’t want them to merge up, they still run into that plane. Is there any way to get around that to manage vertical merging?
    [10:21 PM]
    Or is there a way to this car system without needing to put a “track” with a collider under the cars?
     
  46. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,507
    Hello, at this point there are obviously tricks going on to achieve the result, another option you may consider is giving the cars 2 layers that get swapped based on if a car is merging, and use the layer collision matrix to determine which layers can collide. For example, only a merging car layer can collide with the invisible ramp layer. With this you'd likely have to hack at the code a bit to change the car layers based on the 2 states since it's not something that's built into the system.
     
  47. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,507
    Version 1.0.44 submitted.

    • Fixed a bug where align AITrafficWaypointRoute.AlignPoints would not apply the proper rotation to the final waypoint.
    • Improved movement logic to use frontSensorTransformPosition instead of carTransformPosition for more accurate distance checking while braking.
     
  48. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    935
    Hi. Great system. I checked most of the videos but not all posts here.

    Do you plan to extend it with some base features so that a time of day/week system becomes easily possible.

    There minimum requirements would be

    - mass parking place like supernarket or work
    - normal parking place for home or side of street

    Then you could create on a timeline

    Car A
    • 6.00 AM start from home parking place
    • 6.20 parking place gas station
    • 8.00 parking place work
    • 12.00 drive to parking place for lunch
    • 15.00 drive to parking place super market
    • 15.30 drive to parking place home
    For about 100 to 300 cars (depending on map size) there is such an timeline.

    The rest could be filled up with pooled traffic like already possible
    e.g. spawn additional
    50 cars in the morning hours
    100 cars in the evening hours
    10 at night
    around player.

    Together this would generate a more realistic simulation.
    It s more like the charakters in RDR2 behave. Some have a full day cycle and run around.
    Some are spawned around player.


    FYI
    I played around with codewalker who loads the original installed game level from GTA 5 including paths and navmeshes.

    It was a great learning source.
    This is what you get in the Editor.
    They have a reduced spline setup. One Spline per road. Think they work with lane offsets from the main spline.

    001_Paths003.JPG 001_Paths001_andNavmesh.JPG 001_Paths002.JPG 001_Paths001.JPG

    Btw. Edy from Vehicle Physics Pro developed a "autonomous" fake drive function on our request
    You can drive around with your car and on key press it searchs the closed point to the closest spline and drives automated on this. You can overtake steering evertime you want again.

    He also developed some PID controler to get smooth to different speeds when car physics is guided by the spline.

    I would love to connect it with your system.
     
    Last edited: Jan 10, 2021
    Stephen_O likes this.
  49. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,507
    Thanks for the question, and sharing a notes about your research, it's very interesting.

    STS has been a passion project form me, I've been iterating on AI logic and doing various R&D for a about 3-5 years in my spare time. About a year ago the first version of STS was released, using Unity's new job system. It was developed based on a need for more optimized traffic in my own game prototype, and requests from others who wanted to use it in their projects (I was sharing my work via devlogs on YouTube). I haven't really earned enough from it to be able to focus full time on R&D and continued iteration - though I wouldn't mind doing it full time if I was able to achieve a truly AAA system. I'm sure Rockstar has at least a few devs that developed their traffic system, being paid to work full time, and collaborate together for their result over multiple years - the scope for their system is a bit large for me to handle.

    Because it's a passion project, I will likely always continue to improve it over time; programing AI is fun for me. I don't know if/when I will move to a spline based system, or a hybrid system supporting both, as that would basically be a complete rewrite from the current waypoint based method. Using waypoints over splines allows AI to be more dumb (by not requiring updates every frame, and only knowing where they are going next, based on the previous OnReachWaypoint callback via OnTriggerEnter callback from waypoint colliders), but also have a robust set of options available for each point, allowing for modularity, and easy customization.

    I've recieved a lot of requests for destination pathfinding, this is somethign I'm interesting in doing R&D for, though I have not yet started to test anything. It's likely possible for a knowledgable Unity programmer to create that functionality through the currently available API, with some minor modifactions to the source, as a layer upon the current system; though I know what you're asking for is for it to be available without requing you to write the logic yourself.

    It is currently possible for you to register/unregister cars from AI processing at runtime, to allow player interactions. A couple users that I know of have done this to create GTA style player interactions. If you want a player car to turn autonomous, it just needs to be regestered with the AITrafficController, then to set a car's waypoint/route via code you will need to have a reference to the AITraffciCar script attached to the car and call:
    ChangeToRouteWaypoint(AITrafficWaypointSettings onReachWaypointSettings)

    This method will need to be passed AITrafficWaypoint.onReachWaypointSettings from the waypoint you want the car to use.
     
  50. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,507
    I've been working on a CiDy STS integration with the developer of CiDy, we think we're almost done, and in final stages of testing: