Giter Site home page Giter Site logo

unity-traffic-simulation's People

Contributors

mandroide avatar mchrbn avatar mschmoecker avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

unity-traffic-simulation's Issues

New Cars collides with others

I added new cars and I used Vehicle Phycischs script but other cars hits the new car and new car hits old ( from prefab) cars. Also my new car always wait on Intersection even if there is no car.
image

Set Passive - Active problem

Hello. I am making a mobile game and I am using your system (thank you for the system ) I have a lot of cars in the scene currently (40 -50) and I have 3 traffic system. It was really laggy because of the AI car and vehicle psychics so I decided to make them passive and active whenever my car enter the their area ( box collider) it almost worked well expect a big bug. As I understand when I make the AI Cars passive and when I come back to the same point cars that in the intersection area ( probably cars that have to stop bool) just stuck and never move again. In video I tried to capture I hope you can see it. I can share my project with you if you want to see what is the problem. Also, I want to share my project with you to show about I could not able to add new cars with AI system.

video of the bug you can see the car which I zoomed totally stucked
https://youtu.be/EqACDfeV7SU
That is my performance code

ss.txt
image

Editor Todo

I really like this project and here is a list of things I want to make for the current system. If I find some time of course :)

Todo

  • Snap tools
  • Intersection editing
    • directly edit the size of boxcollider/remove it and make a custom system
    • better tools for stop signs and traffic lights?
    • Linking segments together
  • Waypoints
    • add points in between of existing ones
    • option to add a new point as the last point
  • Code Cleanup
    • Move Gizmos to own class
    • Move Inspector drawing to own class
  • Gizmos
    • Segment label not clear at the moment (if two are close together)
    • equal hight of strokes (currently some are at y=0, and some on y = 1)

Done

  • Easy moving of waypoints
  • Undo in the Editor
  • Arrows for strokes

And here are some thoughts I have to left

  • Waypoints for curves? This would make sense with a better CarAI
  • Waypoint system + NavMesh doesn't really fit, it seems doubled. I completely understand why the NavMes is used, but from my point of view it can be removed in the future and use a more customized system (together with a new CarAI)
  • The component initialisation is confusing/forbids prefabs (like #6)
  • in my workflow I have tiles of roads, so linking Waypoints to prefabs and then joining them/let them automatically join with rule patters
  • Maybe some sort of vocabulary/keyword collection. I often struggle with certain words like what to call the lines between waypoints

I am open for any discussion^^

Cars crashing into each other at intersections

I have no idea why it's happening, but the cars are constantly crashing into each other. I just opened the example scene and it's not working. Maybe someone knows why this is happening...

Desktop 2020 09 02 - 17 40 02 01_Moment(2)
Desktop 2020 09 02 - 17 40 02 01_Moment(3)
Desktop 2020 09 02 - 17 40 02 01_Moment

Script errors in 5.6.7f1

When I open a project on Unity 5.6.7F1, I see CS4.0 errors, on this I installed SC6Supprot and get only two errors:
Assets\TraficSimulation\Scripts\Editor\TrafficEditor.cs(94,40) error CS1525: Invalid expression term 'float'
Assets\TraficSimulation\Scripts\Editor\TrafficEditor.cs(148,77) error CS1525: Invalid expression term 'bool'
Search for solutions on the Internet did not give results ... How to solve the problem?

P.S. I am not going to install newer editor versions, because it does not pull the computer and there is no support for DX9, which is very important to me

isdirty

unity editor giving me these error , any idea?
Assets\unitysimulation\Assets\TrafficSimulation\Scripts\Editor\TrafficEditor.cs(292,32): error CS0117: 'EditorUtility' does not contain a definition for 'IsDirty'

Failed to load 'C://testing/test/Assets/unitysimulation/Assets/TrafficSimulation/Examples/Scenes/Example_01/LightingData.asset' because it was serialized with a newer version of Unity. (Has a higher SerializedFile version)
UnityEditorInternal.InternalEditorUtility:ProjectWindowDrag(HierarchyProperty, Boolean)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

Update to Unity's new input system

Hello,

I would like to use your tool in my project but since I'm using the new input system, I think all the controls don't work:
After creating the Traffic System game object, when I select it and then I press Ctrl + Left Click or Shift + Left Click in the scene, nothing happens.
Basically it's selecting the game objects in the scene I already created.

Thank you

Doesnt follow waypoints

Hello, I am trying to understand your system for long time. I am new on unity and codding and github :) I made a city for my taxi game and i used your system . But when cars get collision or they leave the waypoints they dont come back the red line. So I made a system only by Segments it worked but that time every car want to go Segment 0 first. I hope you understand the situation my english not very good .

Thanks for the system

Recommendation for performance boost

Hi!
Some months ago i did peque-traffic . I'm 100% sure you won't like the way it's coded & etc, so don't look at it. I wanted to share with you a heavy improvement that i applied to it recently (i didn't push it to the repo yet).

On runtime, all waypoints are converted to basic data classes and all scene waypoints are deleted to avoid having their Monobehaviours. Doing that i got a gain of over 27fps.

On my tests (with my package in Editor mode on Unity 2019.3.7f1):
Having 55 vehicles & over 220 waypoints made the scene drop to 45FPS. Removing the vehicles did nothing, while deleting all waypoints increased them to 72FPS.

Frames were measured with:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

[RequireComponent(typeof(Text))]
public class FPSCounter : MonoBehaviour
{
    const float fpsMeasurePeriod = 0.5f;
    private int m_FpsAccumulator = 0;
    private float m_FpsNextPeriod = 0;
    private int m_CurrentFps;
    const string display = "{0} FPS";
    private Text m_Text;


    private void Start() {
        m_FpsNextPeriod = Time.realtimeSinceStartup + fpsMeasurePeriod;
        m_Text = GetComponent<Text>();
    }


    private void Update() {
        // measure average frames per second
        m_FpsAccumulator++;
        if (Time.realtimeSinceStartup > m_FpsNextPeriod) {
            m_CurrentFps = (int)(m_FpsAccumulator / fpsMeasurePeriod);
            m_FpsAccumulator = 0;
            m_FpsNextPeriod += fpsMeasurePeriod;
            m_Text.text = string.Format(display, m_CurrentFps);
        }
    }
}

Hope it helps!

deleting waypoint gives continous error

hi this is amazing code , but deleting way point gives continuous error till i delete traffic system , this makes it hard to make own traffic system , i hope u take a look in that ๐Ÿฅ‡ ๐Ÿ’ฏ

Mobile Performance

I am using traffic simulation happily on my project as you know. I use it for AI cars in my city. When there are 10 - 20 cars active my FPS drop to 600 to 300 ( on editor on computer 960m i5 6300hq) I am still trying to aim 60FPS for some 3 - 4 years old mobile phones ( now I get 30 - 40 but when I profile it the most expensive things AI car and AI car's physics ) but it is very hard with that. I know you are going to start to take a look on this asset when you are not bussy or if you want to. I wanted to list this issue if you can solve whenever you start to work on this asset again.

Lots of errors

On unity 2018.4.2f1 I get a ton of errors all over the place. Tried using both latest release and git version. Here's a sample of two:

on open example scene, it does run though:

NullReferenceException: Object reference not set to an instance of an object TrafficSimulation.Waypoint.OnDrawGizmos () (at Assets/TrafficSimulation/Scripts/Waypoint.cs:18) UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

On attempting to follow tutorial (ctrl click to place) I get:
UnityException: Transform child out of bounds TrafficSimulation.TrafficEditor.AddSegment (UnityEngine.Vector3 position) (at Assets/TrafficSimulation/Scripts/Editor/TrafficEditor.cs:97) TrafficSimulation.TrafficEditor.OnSceneGUI () (at Assets/TrafficSimulation/Scripts/Editor/TrafficEditor.cs:44) System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <d7ac571ca2d04b2f981d0d886fa067cf>:0) Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation. System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <d7ac571ca2d04b2f981d0d886fa067cf>:0) System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at <d7ac571ca2d04b2f981d0d886fa067cf>:0) UnityEditor.SceneView.CallOnSceneGUI () (at C:/buildslave/unity/build/Editor/Mono/SceneView/SceneView.cs:2836) UnityEditor.SceneView.HandleSelectionAndOnSceneGUI () (at C:/buildslave/unity/build/Editor/Mono/SceneView/SceneView.cs:2125) UnityEditor.SceneView.OnGUI () (at C:/buildslave/unity/build/Editor/Mono/SceneView/SceneView.cs:1986) System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <d7ac571ca2d04b2f981d0d886fa067cf>:0) Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation. System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <d7ac571ca2d04b2f981d0d886fa067cf>:0) System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at <d7ac571ca2d04b2f981d0d886fa067cf>:0) UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:342) UnityEditor.HostView.Invoke (System.String methodName) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:336) UnityEditor.HostView.InvokeOnGUI (UnityEngine.Rect onGUIPosition, UnityEngine.Rect viewRect) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:310) UnityEditor.DockArea.DrawView (UnityEngine.Rect viewRect, UnityEngine.Rect dockAreaRect, System.Boolean customBorder, System.Boolean floatingWindow, System.Boolean isBottomTab) (at C:/buildslave/unity/build/Editor/Mono/GUI/DockArea.cs:361) UnityEditor.DockArea.OldOnGUI () (at C:/buildslave/unity/build/Editor/Mono/GUI/DockArea.cs:320) UnityEngine.Experimental.UIElements.IMGUIContainer.DoOnGUI (UnityEngine.Event evt, UnityEngine.Matrix4x4 worldTransform, UnityEngine.Rect clippingRect, System.Boolean isComputingLayout) (at C:/buildslave/unity/build/Modules/UIElements/IMGUIContainer.cs:266) UnityEngine.Experimental.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, UnityEngine.Matrix4x4 worldTransform, UnityEngine.Rect clippingRect) (at C:/buildslave/unity/build/Modules/UIElements/IMGUIContainer.cs:438) UnityEngine.Experimental.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e) (at C:/buildslave/unity/build/Modules/UIElements/IMGUIContainer.cs:421) UnityEngine.Experimental.UIElements.IMGUIContainer.HandleEvent (UnityEngine.Experimental.UIElements.EventBase evt) (at C:/buildslave/unity/build/Modules/UIElements/IMGUIContainer.cs:401) UnityEngine.Experimental.UIElements.EventDispatcher.PropagateEvent (UnityEngine.Experimental.UIElements.EventBase evt) (at C:/buildslave/unity/build/Modules/UIElements/EventDispatcher.cs:754) UnityEngine.Experimental.UIElements.EventDispatcher.ProcessEvent (UnityEngine.Experimental.UIElements.EventBase evt, UnityEngine.Experimental.UIElements.IPanel panel) (at C:/buildslave/unity/build/Modules/UIElements/EventDispatcher.cs:599) UnityEngine.Experimental.UIElements.EventDispatcher.Dispatch (UnityEngine.Experimental.UIElements.EventBase evt, UnityEngine.Experimental.UIElements.IPanel panel, UnityEngine.Experimental.UIElements.DispatchMode dispatchMode) (at C:/buildslave/unity/build/Modules/UIElements/EventDispatcher.cs:307) UnityEngine.Experimental.UIElements.BaseVisualElementPanel.SendEvent (UnityEngine.Experimental.UIElements.EventBase e, UnityEngine.Experimental.UIElements.DispatchMode dispatchMode) (at C:/buildslave/unity/build/Modules/UIElements/Panel.cs:176) UnityEngine.Experimental.UIElements.UIElementsUtility.DoDispatch (UnityEngine.Experimental.UIElements.BaseVisualElementPanel panel) (at C:/buildslave/unity/build/Modules/UIElements/UIElementsUtility.cs:245) UnityEngine.Experimental.UIElements.UIElementsUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at C:/buildslave/unity/build/Modules/UIElements/UIElementsUtility.cs:68) UnityEngine.GUIUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at C:/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:179)

Trafic System doesn't work on Prefab Objects

If I attach the TrafficSystem script to a prefab, it will basicly re-Instantiate that object, therefor losing segments and intersections saved during edit. The solution is simply not using a prefab, but I feel as you could set a fallback if he doesn't find any segments, to check his child objects for them :D

Any tips for optimizing?

This isn't really an issue, the traffic system works perfectly but the maps I'm using it on are huge, so it has very bad performance.

Do you have any suggestions for optimizing the system on big maps? I'm new to the scripting stuff on Unity so I don't know much.

Problems with new update

Hello, I tried the new update. When there is an accident one car goes back it is amazing feature ! But I find a problem.

https://youtu.be/gnGZqEFc6OM

  1. Cars dont follow the road ( they follow but with very wide angle) especially on the turns they just go out of the road. It causes to a lot of accident and cars get stuck because of it. I tested your example scene it also had the same problem. Traffic goes crazy in 2 minutes. If you remember I was using a lot of segments so cars were following the exact road. Also, it did not work in this update.

// small suggestions
2. I think downforce should be added to avoid turn over car.

  1. I added wheel size option. May some people will need that small feature as well.

` public Vector3 whellsSize = new Vector3(1f, 1f, 1f);

    [Tooltip("Whether you want to animate the wheels")]
    public bool animateWheels = true;
    
    [Tooltip("The vehicle's drive type: rear-wheels drive, front-wheels drive or all-wheels drive.")]
    public DriveType driveType;

    private WheelCollider[] wheels;
    private float currentSteering = 0f;

    void OnEnable(){
        wheels = GetComponentsInChildren<WheelCollider>();

        for (int i = 0; i < wheels.Length; ++i) 
        {
            var wheel = wheels [i];

            // Create wheel shapes only when needed.
            if (leftWheelShape != null && wheel.transform.localPosition.x < 0)
            {
                var ws = Instantiate (leftWheelShape);
                ws.transform.parent = wheel.transform;
                ws.transform.localScale = whellsSize;
            }
            else if(rightWheelShape != null && wheel.transform.localPosition.x > 0){
                var ws = Instantiate(rightWheelShape);
                ws.transform.parent = wheel.transform;
                ws.transform.localScale = whellsSize;
            }`

Slow Car Bug

Hello. It happens espically when you wait long time. A car starts to go slow and others have to wait for it. I dont know what is the reason of it maybe it can be intersections.

https://youtu.be/kkPRa0npxcs

Raycast Not working

cars are not detecting cars in front of it and not stopping or slowing down.
I can see rays when playing but it not working.

Vehicles collides with waypoint

Hello!

Thank you for sharing such a great sytem. I've been trying to implement it on my project and I have only one issue. When a vehicle approach a waypoint it create a collision, yet every parameters with your demo version are the same. I've tried nearly everything but it's still doesn't seems to work. Layers and tags are set, colliders are also set on vehicles and waypoints,

I'm using last version of your code and last version of Unity, thx for your help!

Unable to build

when i try to build the example i get the following error messages and the build fails:

Assets\TrafficSimulation\Scripts\TrafficSystem.cs(19,10): error CS0246: The type or namespace name 'MenuItemAttribute' could not be found (are you missing a using directive or an assembly reference?)

Assets\TrafficSimulation\Scripts\TrafficSystem.cs(19,10): error CS0246: The type or namespace name 'MenuItem' could not be found (are you missing a using directive or an assembly reference?)

Error building Player because scripts had compiler errors

VehicleAI doesn't recognize segment

this is propably something I Wrote wrong in the script. I placed all my roades and when I place my car and put the vehicleAI and Wheeldrive on it it doesn't move, I think this is becouse it doesn't see the segment. do you have any way that I could fix this? Do I need a layer or tag on the segments?

I love what you have done.
Regards
perihelium

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.