Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Simple Traffic System

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

  1. fady_samh

    fady_samh

    Joined:
    May 14, 2020
    Posts:
    2
    error CS0246: The type or namespace name 'VehicleTypes' could not be found (are you missing a using directive or an assembly reference?)
    i receive this error when importing the package to the unity project
     
  2. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510

    VehicleTypes is not a namespace in STS.
    All scripts from STS are in namespace TurnTheGameOn.SimpleTrafficSystem.
     
  3. AuKtagon

    AuKtagon

    Joined:
    Aug 3, 2017
    Posts:
    7
    I'd love to ask before buying. I am looking to use another Car AI asset that just follows a world position as best as it can. Is it easy to simply use another asset for each car instead of using the built in cars themselves?
     
  4. Homicide

    Homicide

    Joined:
    Oct 11, 2012
    Posts:
    660
    In my experience, the minute you want to use an AI that is not the provided AI for traffic systems... is the minute the traffic system starts to fall apart.
     
  5. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    STS is a controller, and just like any other controller, it's only designed to work with this package.

    This is correct. I don't know of any AI controllers that can 'just work' with any other vehicle physics or AI packages - each developers tends to do things in different ways, there are no standards.
     
  6. baibiantianhou

    baibiantianhou

    Joined:
    Jan 9, 2023
    Posts:
    1
    Hello there! When I try to draw the route points while pressing SHIFT button, the route points always float in the air without tightly attaching to the ground. Is there any technique can help sovle this problem?
     
  7. schrotti26

    schrotti26

    Joined:
    Oct 4, 2020
    Posts:
    3
    Hey there,
    how does the system handle streets that may be rotated along 2 axis? Is there an option to project the cars to always fit the road? something like that?

    Thanks
     
  8. melksnis

    melksnis

    Joined:
    Sep 30, 2020
    Posts:
    10
    Hello. I have a problem I use floating point fix in my game -that is I shift all gameobject when moved too far from origin. How can I reset car target points after I shifting. they are stored somewhere and car still wants to go to their previous locations except some that happened to reach it my accident the moment I shifted..
     
  9. melksnis

    melksnis

    Joined:
    Sep 30, 2020
    Posts:
    10
    well it worked with this
    AITrafficController.Instance.Set_RoutePointPositionArray(GetComponent<AITrafficCar>().assignedIndex);
    also any way to use yield trigger without traffic lights - I have big map and there are lets say highway and small road connecting to it. I want car to go that small road and check if no cars are coming and then drive on it
     
  10. kevindavis12345

    kevindavis12345

    Joined:
    Apr 26, 2023
    Posts:
    1
    Is there any way of disabling those green lines that point to the next waypoint? There are so many in may scene and it is distracting.
     
  11. RetrKill0

    RetrKill0

    Joined:
    Sep 4, 2022
    Posts:
    7
    Hi, I'm still new with the asset, at least I didn't find an option other than the one in configure mode spawn Points. it has the option "setup random spawn Points", but it only works if you click on it, it would be possible to add an option in the AITrafficController that we enable the spawn randown every time the game starts or the script is reloaded (eg when we put loading in the game)

    And in the AITrafficWaypointRoute, in addition to having the option use spawn points, it also has "random spawn", that way the traffic will always be dynamic
     
  12. FerjadAli

    FerjadAli

    Joined:
    Aug 4, 2020
    Posts:
    1
    i'm having this issue when i check the usePooling it generates the error mentioned below other wise it works fine

    so i was comparing with the demopooling scene and everything seems to be fine

    can anyone help ? urgently
    NullReferenceException: Object reference not set to an instance of an object
    Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle.CheckWriteAndThrow (Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle handle) (at <ab74fe8c3de74feeafac966c034df8aa>:0)
    UnityEngine.Jobs.TransformAccessArray.GetTransformAccessArrayForSchedule () (at <ab74fe8c3de74feeafac966c034df8aa>:0)
    UnityEngine.Jobs.IJobParallelForTransformExtensions.Schedule[T] (T jobData, UnityEngine.Jobs.TransformAccessArray transforms, Unity.Jobs.JobHandle dependsOn) (at <ab74fe8c3de74feeafac966c034df8aa>:0)
    TurnTheGameOn.SimpleTrafficSystem.AITrafficController.FixedUpdate () (at Assets/TurnTheGameOn/SimpleTrafficSystem/Scripts/AITrafficController.cs:262)
     
  13. Patrioc_plays

    Patrioc_plays

    Joined:
    Apr 29, 2021
    Posts:
    4
    Yooo cool asset but is there a way to change how the cars slow down/brake, cuz sometimes they just instantly stop instead of slowing down and stopping and it looks rlly bad
     
  14. Colin_MacLeod

    Colin_MacLeod

    Joined:
    Feb 11, 2014
    Posts:
    336
    I upgraded Unity to 2022.3.8 and am now seeing 3 warnings:


    Code (csharp):
    1. Assets/TurnTheGameOn/SimpleTrafficSystem/Scripts/AITrafficController.cs(841,25): warning CS0618: 'BoxcastCommand.BoxcastCommand(Vector3, Vector3, Quaternion, Vector3, float, int)' is obsolete: 'This struct signature is no longer supported. Use struct with a QueryParameters instead'
    2. Assets/TurnTheGameOn/SimpleTrafficSystem/Scripts/AITrafficController.cs(852,58): warning CS0618: 'BoxcastCommand.BoxcastCommand(Vector3, Vector3, Quaternion, Vector3, float, int)' is obsolete: 'This struct signature is no longer supported. Use struct with a QueryParameters instead'
    3. Assets/TurnTheGameOn/SimpleTrafficSystem/Scripts/AITrafficController.cs(857,59): warning CS0618: 'BoxcastCommand.BoxcastCommand(Vector3, Vector3, Quaternion, Vector3, float, int)' is obsolete: 'This struct signature is no longer supported. Use struct with a QueryParameters instead'
    Any suggestions?
     
  15. Patrioc_plays

    Patrioc_plays

    Joined:
    Apr 29, 2021
    Posts:
    4
    That likely isn't going to do much at all, you can ignore them I'm fairly sure
     
    Colin_MacLeod likes this.
  16. Colin_MacLeod

    Colin_MacLeod

    Joined:
    Feb 11, 2014
    Posts:
    336
    So I don't miss something important, I try to keep the console warning-free.

    I'll add pragmas to the code to ignore these for now :)
     
  17. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    Thanks for letting me know!

    I created a new package for 2022 LTS to support Collections to 2.1.4 and BoxcastCommand using QueryParameters.

    New package link:
    https://assetstore.unity.com/packag...e-traffic-system-2022-lts-265560?aid=1011lGiG
     
  18. Colin_MacLeod

    Colin_MacLeod

    Joined:
    Feb 11, 2014
    Posts:
    336
    Oh, nice! Thank you. I'll check it out.
     
  19. Patrioc_plays

    Patrioc_plays

    Joined:
    Apr 29, 2021
    Posts:
    4
    NullReferenceException: Object reference not set to an instance of an object
    TurnTheGameOn.SimpleTrafficSystem.AITrafficController.FixedUpdate () (at Assets/TurnTheGameOn/SimpleTrafficSystem/Scripts/AITrafficController.cs:830)

    Im getting this error whenever I turn on "Front sensor faces target" option in the AI traffic controller script
    Like it works fine for the first maybe.. 10 seconds and then I get this error and all the AI traffic vehicles go crazy, like they just speed up randomly, dont follow their way points and stuff
     
  20. shounak00_unity

    shounak00_unity

    Joined:
    Sep 10, 2020
    Posts:
    13
    So is there any Way I can use your traffic system where I can stop the card in it's track completely. Get the door open. and site and drive the car?
     
  21. shounak00_unity

    shounak00_unity

    Joined:
    Sep 10, 2020
    Posts:
    13
    More like gta v style?
     
  22. Colin_MacLeod

    Colin_MacLeod

    Joined:
    Feb 11, 2014
    Posts:
    336
    I believe you can do this with code. I don't have the methods to hand but you would detach your car from the system by making it no longer a follower.
     
  23. CarlAndren02

    CarlAndren02

    Joined:
    Dec 13, 2023
    Posts:
    2
    I get the error:

    ExecuteMenuItem failed because there is no menu named 'Edit/Render Pipeline/Upgrade Project Materials to High Definition Materials'
    UnityEditor.EditorApplication:ExecuteMenuItem (string)
    TurnTheGameOn.SimpleTrafficSystem.Editor_STSWindow:OnGUI () (at Assets/TurnTheGameOn/SimpleTrafficSystem/Scripts/Editor/Editor_STSWindow.cs:123)
    UnityEngine.GUIUtility:processEvent (int,intptr,bool&)

    When I click on Update Projects Materials for HDRP
     
  24. RetrKill0

    RetrKill0

    Joined:
    Sep 4, 2022
    Posts:
    7
    hello, firstly have a good end of the year. Can anyone help me?
    I'm trying to make collision work on npc cars, but I'm possibly having a problem with the mass of the rigidbody because the player can set it from 1 to 10 and the npcs can set this value to equalize the bad lol the vehicle simply disappears because it's so light, I tried do the script below. To make things easier, I threw this script into GPT chat to create comments. Note, I still have the old version and I'm already taking advantage of it and asking if I need to do this with the new one or not?


    using System.Collections;
    using TurnTheGameOn.SimpleTrafficSystem;
    using UnityEngine;

    public class CollisionHandler : MonoBehaviour
    {
    public AITrafficCar aiTrafficCar; // Reference to the AI car script
    public float minCollisionVelocity = 0.1f; // Minimum velocity for collision detection
    public bool applyCollisionLogic = true; // Option to apply collision logic or not.

    private bool isCollisionHandled = false; // Flag to track if collision has been handled
    private Vector3 initialPosition; // Store the initial position of the NPC before the collision

    private float originalMassValue; // Store the original mass value of the NPC's Rigidbody
    private float originalDragValue; // Store the original drag value of the NPC's Rigidbody

    private void OnCollisionEnter(Collision collision)
    {
    Debug.Log("Colisão detectada!");
    if (applyCollisionLogic && collision.relativeVelocity.magnitude >= minCollisionVelocity && !isCollisionHandled)
    {

    if (collision.collider.CompareTag("Player"))
    {
    Rigidbody playerRigidbody = collision.collider.GetComponent<Rigidbody>();
    if (playerRigidbody != null)
    {
    // To dynamically adjust the NPC's Rigidbody values to match those of the player.
    Rigidbody npcRigidbody = aiTrafficCar.GetComponent<Rigidbody>();
    npcRigidbody.mass = Mathf.Clamp(playerRigidbody.mass, 1f, 10f);
    npcRigidbody.drag = playerRigidbody.drag;
    }

    }
    // Disable AI processing when a collision with sufficient velocity is detected
    aiTrafficCar.DisableAIProcessing();

    // Reset the car's position to the initial position
    transform.position = initialPosition;

    // Check the car's Rigidbody.velocity to determine when it stops moving
    StartCoroutine(WaitForCarToStop());

    }
    }

    IEnumerator WaitForCarToStop()
    {
    while (aiTrafficCar.GetComponent<Rigidbody>().velocity.magnitude > 0.1f)
    {
    yield return null;
    }

    // Re-enable AI processing and update target waypoints/headings
    aiTrafficCar.EnableAIProcessing();

    // Restore the NPC's Rigidbody to its original values
    Rigidbody npcRigidbody = aiTrafficCar.GetComponent<Rigidbody>();
    npcRigidbody.mass = originalMassValue; // Replace originalMassValue with the desired original value
    npcRigidbody.drag = originalDragValue; // Replace originalDragValue with the desired original value

    isCollisionHandled = true; // Set this to avoid handling multiple collisions
    }
    }


    there are 2 problems: 1 the car hits the npc and he disappears
    2 sometimes the NPC throws me away lol


    Update
    Now i using the new version with suport unity 2022
     
    Last edited: Dec 19, 2023
  25. kadykunde

    kadykunde

    Joined:
    Oct 23, 2017
    Posts:
    1
    Lately I've been using STS and loving it but have encountered a few problems with the pooling system that I've been struggling to fix, and I was wondering if I'm messing up the setup somehow, or if these are known problems.

    1. Some routes don't spawn cars while others are completely full. I have made sure that there are a lot of spawn points in them and that there are enough cars in the pool to populate them. The problem always seems to happen in the same routes, and I have double checked to make sure they're configured the same exact way as the ones that work fine, so I don't know what could be causing this.

    2. After the scene runs for a while, cars seem to stop spawning? I also notice that there are a lot of active car objects falling into the void in the "Disabled Car Position". It's as if the pool of cars is not getting reused properly. Is this a known configuration problem, or some kind of bug?
     
  26. garamanx

    garamanx

    Joined:
    Apr 3, 2019
    Posts:
    11
    Hi! I have 2 vehicle types, "default" and "custom". I want the custom type cars to be forced to take routes on intersections by giving one new route all types and the other route default type only. So I try to "forbid" custom cars routes by this method. Is this correct?
    Best, Max
     
  27. lonewolf4_

    lonewolf4_

    Joined:
    May 20, 2019
    Posts:
    2
    I add everything to my project without any problems, but when I open the pooling option, I get the following error code in the console.
    It works smoothly in the demo scene, but it only gives an error when I try to build a straight road. Moreover, I only get this error when pooling is on, if it is turned off, it works actively.


    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. UnityEngine.Jobs.TransformAccessArray.GetTransformAccessArrayForSchedule () (at <53aac14d88ba4477acc998b039cfd73a>:0)
    3. UnityEngine.Jobs.IJobParallelForTransformExtensions.Schedule[T] (T jobData, UnityEngine.Jobs.TransformAccessArray transforms, Unity.Jobs.JobHandle dependsOn) (at <53aac14d88ba4477acc998b039cfd73a>:0)
    4. TurnTheGameOn.SimpleTrafficSystem.AITrafficController.FixedUpdate () (at Assets/TurnTheGameOn/SimpleTrafficSystem/Scripts/AITrafficController.cs:262)
    bandicam 2024-01-26 01-27-08-722.jpg
     
  28. Patrioc_plays

    Patrioc_plays

    Joined:
    Apr 29, 2021
    Posts:
    4
    I keep getting these two errors whenever i switch scenes


    First:
    Code (CSharp):
    1. ObjectDisposedException: The Unity.Collections.NativeList`1[System.Boolean] has been deallocated, it is not allowed to access it
    2. Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle.CheckReadAndThrowNoEarlyOut (Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle handle) (at <acc21e65c0ae4adf80ac80bfa5d3f603>:0)
    3. Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle.CheckReadAndThrow (Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle handle) (at <acc21e65c0ae4adf80ac80bfa5d3f603>:0)
    4. Unity.Collections.NativeList`1[T].get_Item (System.Int32 index) (at Library/PackageCache/com.unity.collections@0.9.0-preview.6/Unity.Collections/NativeList.cs:124)
    5. TurnTheGameOn.SimpleTrafficSystem.AITrafficController.GetIsDisabled (System.Int32 _index) (at Assets/TurnTheGameOn/SimpleTrafficSystem/Scripts/AITrafficController.cs:237)
    6. TurnTheGameOn.SimpleTrafficSystem.Editor_AITrafficController.CustomOnSceneGUI (UnityEditor.SceneView sceneview) (at Assets/TurnTheGameOn/SimpleTrafficSystem/Scripts/Editor/Editor_AITrafficController.cs:46)
    7. UnityEditor.SceneView.CallOnSceneGUI () (at <6a4b923691b54d0eb965a9ed2a807ce9>:0)
    8. UnityEditor.SceneView.HandleSelectionAndOnSceneGUI () (at <6a4b923691b54d0eb965a9ed2a807ce9>:0)
    9. UnityEditor.SceneView.OnGUI () (at <6a4b923691b54d0eb965a9ed2a807ce9>:0)
    10. UnityEditor.HostView.InvokeOnGUI (UnityEngine.Rect onGUIPosition, UnityEngine.Rect viewRect) (at <6a4b923691b54d0eb965a9ed2a807ce9>:0)
    11. UnityEditor.DockArea.DrawView (UnityEngine.Rect viewRect, UnityEngine.Rect dockAreaRect) (at <6a4b923691b54d0eb965a9ed2a807ce9>:0)
    12. UnityEditor.DockArea.OldOnGUI () (at <6a4b923691b54d0eb965a9ed2a807ce9>:0)
    13. UnityEngine.UIElements.IMGUIContainer.DoOnGUI (UnityEngine.Event evt, UnityEngine.Matrix4x4 parentTransform, UnityEngine.Rect clippingRect, System.Boolean isComputingLayout, UnityEngine.Rect layoutSize, System.Action onGUIHandler, System.Boolean canAffectFocus) (at <d974896ca161484b850e08c9ee63651b>:0)
    14. UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, UnityEngine.Matrix4x4 worldTransform, UnityEngine.Rect clippingRect, System.Action onGUIHandler, System.Boolean canAffectFocus) (at <d974896ca161484b850e08c9ee63651b>:0)
    15. UnityEngine.UIElements.IMGUIContainer.DoIMGUIRepaint () (at <d974896ca161484b850e08c9ee63651b>:0)
    16. UnityEngine.UIElements.UIR.RenderChainCommand.ExecuteNonDrawMesh (UnityEngine.UIElements.UIR.DrawParams drawParams, System.Single pixelsPerPoint, System.Exception& immediateException) (at <d974896ca161484b850e08c9ee63651b>:0)
    17. Rethrow as ImmediateModeException
    18. UnityEngine.UIElements.UIR.RenderChain.Render () (at <d974896ca161484b850e08c9ee63651b>:0)
    19. UnityEngine.UIElements.UIRRepaintUpdater.Update () (at <d974896ca161484b850e08c9ee63651b>:0)
    20. UnityEngine.UIElements.VisualTreeUpdater.UpdateVisualTreePhase (UnityEngine.UIElements.VisualTreeUpdatePhase phase) (at <d974896ca161484b850e08c9ee63651b>:0)
    21. UnityEngine.UIElements.Panel.UpdateForRepaint () (at <d974896ca161484b850e08c9ee63651b>:0)
    22. UnityEngine.UIElements.Panel.Repaint (UnityEngine.Event e) (at <d974896ca161484b850e08c9ee63651b>:0)
    23. UnityEngine.UIElements.UIElementsUtility.DoDispatch (UnityEngine.UIElements.BaseVisualElementPanel panel) (at <d974896ca161484b850e08c9ee63651b>:0)
    24. UnityEngine.UIElements.UIElementsUtility.UnityEngine.UIElements.IUIElementsUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr, System.Boolean& eventHandled) (at <d974896ca161484b850e08c9ee63651b>:0)
    25. UnityEngine.UIElements.UIEventRegistration.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at <d974896ca161484b850e08c9ee63651b>:0)
    26. UnityEngine.UIElements.UIEventRegistration+<>c.<.cctor>b__1_2 (System.Int32 i, System.IntPtr ptr) (at <d974896ca161484b850e08c9ee63651b>:0)
    27. UnityEngine.GUIUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr, System.Boolean& result) (at <e2183e8e6ce34a9f8625fb09a25fb001>:0)
    Second:

    Code (CSharp):
    1. GUI Error: You are pushing more GUIClips than you are popping. Make sure they are balanced.
    2. UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
     
  29. thelocationlabdeveloper

    thelocationlabdeveloper

    Joined:
    Sep 8, 2020
    Posts:
    18
    Hey Stephen,
    This Package is Great, but I am having a Issue.
    Sometime Cars Appear on Top of Other Car which Shouldn't Happen if There is a Car already Why Another car Spawning over it ? Kindly Tell me a Solution For it
    Thanks.
     

    Attached Files:

  30. GOSPODIN18

    GOSPODIN18

    Joined:
    Sep 29, 2021
    Posts:
    2
    When my cars are driving, they constantly slow down every half second, this can be seen from the wheels, the wheels spin intermittently, and when as soon as the front sensor of the car encounters an obstacle, the car immediately stops abruptly for a second, and then gradually approaches the obstacle at a normal distance
     
  31. GOSPODIN18

    GOSPODIN18

    Joined:
    Sep 29, 2021
    Posts:
    2
    I also noticed that in RigidBody Drag and Angular Drag are constantly set to 0 and then returned