mchrbn / unity-traffic-simulation Goto Github PK
View Code? Open in Web Editor NEWA Unity asset that lets you easily simulate very simple traffic into your scene.
A Unity asset that lets you easily simulate very simple traffic into your scene.
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
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)
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
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)
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
Why would that happen, how can i fix it?
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
Done
And here are some thoughts I have to left
I am open for any discussion^^
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
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
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
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.
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!
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.
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!
Hello, I tried the new update. When there is an accident one car goes back it is amazing feature ! But I find a problem.
// small suggestions
2. I think downforce should be added to avoid turn over car.
` 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;
}`
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
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.
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 ๐ฅ ๐ฏ
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.