Skip to content

Traffic3D assets

Note: Most assets on this page have a prefab (a premade item) within the Assets/Resources/Models folder which can be copied or used an example to create / edit your own Assets.

Traffic Lights

Traffic Light Configuration

These are used to control traffic and are used within junctions, the script has the following fields:

  • Traffic Light Id - The traffic light's unique number that identifies the traffic light.
  • Red Material - The material of the red light when it is on.
  • Amber Material - The material of the amber light when it is on.
  • Green Material - The material of the green light when it is on.
  • Black Material - The material of all lights when off.
  • Red Light Object - The circle object for the red light (normally the top light).
  • Amber Light Object - The circle object for the amber light (normally the centre light).
  • Green Light Object - The circle object for the green light (normally the bottom light).
  • Stop Nodes (List) - The nodes on multiple paths where the traffic light stops the vehicles (more on this later).
  • Current Light Colour - The colour of the light that is currently on (e.g. RED, AMBER, GREEN).

Vehicles

Vehicle Engine Configuration

The script has the following fields:

  • Max Steer Angle - The maximum angle at which the vehicle will turn.
  • Turn Speed - The speed at which the wheels will turn.
  • Wheel Collider Front Left - The collider of the front left wheel.
  • Wheel Collider Front Right - The collider of the front right wheel.
  • Max Motor Torque - The maximum torque of the engine in a forward direction.
  • Current Motor Torque - The current torque of the engine in a forward direction.
  • Normal Brake Torque - The torque which the vehicle will normally use for slowing down.
  • Max Brake Torque - The maximum torque which the vehicle will normally use for slowing down.
  • Current Speed - The current speed of the vehicle.
  • Stopping Distance - The distance at which a sensor will signal the vehicle to stop when an object is in front of it.
  • Max Speed - The maximum speed of the vehicle.
  • Distance For Speed Check - A list of distances to evaluate in the speed check turning algorithm (executed when taking corners).
  • Corner Threshold Degrees - The threshold (in degrees) for the speed check turning algorithm to be used when calculating the speed. The bigger the angle, the faster the vehicle will take sharp turns.
  • Corner Sensitivity Modifier - A value which changes the sensitivity of the speed check turning algorithm. The higher the value, the more sensitive the turning algorithm, meaning that the vehicle will slow down more around corners.
  • Corner Min Speed - The minimum speed of the vehicle when going around a corner. Used by the speed check turning algorithm.
  • Stop Distance to Speed - The ratio of distance to speed. Used when slowing down before traffic lights or stop lines.
  • Stop Line Evaluation Distance - The distance between a vehicle and a stop line, at which a vehicle will decide whether to proceed or should stop.
  • Traffic Light Max Speed on Green - The maximum speed at which a vehicle will travel through a green light.
  • Merge Radius Check - The maximum distance the current vehicle will check for other vehicles. Used when merging out from stop lines.
  • Centre Of Mass - The centre of mass of the vehicle.
  • Current Node - The current node of the path the vehicle is on.
  • Current Node Number - The current node number of the path the vehicle is at.
  • Number of Sensor Rays - The number of Sensor rays on the front of the vehicle.
  • Steer Reduce Ray Constant - The value responsible for reducing the distance of the forward collision sensor rays for the vehicle turning algorithm.
  • Max Distance To Monitor - The maximum distance for the sensor rays to monitor.
  • Target Speed - The current target speed of the vehicle.
  • Start Time - The time the vehicle is spawned in at.
  • Start Delay Time - The time when the vehicle has started at the junction.
  • Start Pos - The position the vehicle is spawned in at.
  • Node Reading Offset - The forward offset of the node reader for paths.
  • Engine Status - The status of the Engine currently (e.g. ACCELERATE, STOP, HARD_STOP).
  • Density Count Triggered - Checked when the vehicle has passed the density measurement point.
  • Debug - Shows debug information (currently displays the rays from the sensor).
  • Waiting For Vehicle Ahead (Debug) - Displays the vehicle ahead which is causing the current vehicle to wait.
  • Waiting For Vehicle Behind (Debug) - Displays the vehicle behind which is causing the current vehicle to wait.

Only the following fields should be filled in, the rest of the fields are filled during the simulation:

  • Max Steer Angle
  • Turn Speed
  • Wheel Collider Front Left and Right
  • Max Motor Torque
  • Normal Brake Torque
  • Max Brake Torque
  • Centre Of Mass
  • Number of Sensor Rays
  • Max Distance To Monitor
  • Node Reading Offset
  • Debug

Most of these options can be left at their default values.

Vehicle Factory

Vehicle Factory Configuration

The Vehicle Factory Script has the following fields:

  • High Range Respawn Time - The maximum time in simulation seconds for the next vehicle to re-spawn.
  • Low Range Respawn Time - The minimum time in simulation seconds for the next vehicle to re-spawn.
  • Maximum Vehicle Count - The maximum number of vehicles allowed to be in the scene at once.
  • Slow Down Vehicle Rate At - The number of vehicles in the scene where the rate of spawn will slow down after this number.
  • Time Of Start Invisibility - The amount of time at the start where the spawned vehicle is invisible.
  • Is Left Hand Drive - Checked if the simulation should be in left-hand drive mode (as in the UK).
  • Vehicle Probability (List) - A list of objects which each contain a Vehicles and the probability of that Vehicle spawning next. Probabilities are represented as a float between 0.0 and 1.0 (inclusive). Use this to add extra Vehicles to the scene.
    • Vehicle - The rigidbody of the vehicle.
    • Probability - The probability between 0.0 - 1.0 of the vehicle spawning.
  • Current Vehicles (List) - A list of Vehicles currently in the scene.

Pedestrian Point

Transforms the position at which pedestrians spawn / go to with the PedestrianPoint.cs script attached.

Pedestrians

Pedestrians will walk around the scene by spawning at Pedestrian Points and moving towards another Pedestrian Point as their destination. Models can be created and edited. The Pedestrian Factory will allow multiple models to be added with a probability of the model spawning.

Pedestrian Configuration

The Pedestrian.cs Script has the following fields:

  • Walking In Road Percentage - The chance of the pedestrian walking into the road to reach their destination.
  • Partial Path Fallback Location Distance - This probably won't be edited as much but this is the distance a pedestrian will look around for an original path node to walk back to if their path is suddenly partial (which mainly happens when crossings are turned off) almost like a safe spot for the pedestrian to stand. If no original nodes are found, then they will stand where they are.
  • Max Speed - This is the maximum range of speed they will start with.
  • Min Speed - The minimum speed.
  • Probability of Running - The probability that the pedestrian's speed will be over the set running speed.

There is also a Nav Mesh Agent Component that can be edited too (except for speed as that is decided by the Pedestrian script) which can be found here: https://docs.unity3d.com/Manual/class-NavMeshAgent.html

When creating a pedestrian there are examples within the Assets/Resources/Models/Pedestrians/ folder which can be cloned and used to create new models.

Pedestrian Crossings

The crossing is used by pedestrians to allow them to cross at relevant times. A pedestrian will wait until the crossing allows the pedestrian to cross which are normally changed in a Junction State. PedestrianCrossing.cs has the following fields:

  • Pedestrian Crossing ID – A unique ID to identify the crossing from others.
  • Pedestrian Currently in Crossing Area - The current pedestrians in the area of the crossing.
  • Allow Crossing - A boolean, when true, allows pedestrians to cross roads.

Pedestrian Factory

Creates the pedestrians in the simulation, the script has the following fields:

Pedestrian Factory Configuration

  • Low Range Respawn Time - Lower range for a random time to be generated for the next pedestrians to spawn in simulation seconds (similar to Vehicle respawn time).
  • High Range Respawn Time - The upper range of above in simulation seconds.
  • Maximum Pedestrian Count - The max number of pedestrians that can be in the simulation at once.
  • Pedestrian Probabilities (List) - A list of pedestrian models with the percentage probability of them spawning next. Use this add extra Pedestrian Models.
    • Pedestrian - The Pedestrian.
    • Probability - The probability between 0.0 - 1.0 of the pedestrian spawning.

Pedestrian Manager

This mainly runs in the background, determining which surfaces are roads or pathways for the pedestrians. It also holds a list of the crossings.

The road network

A road network is a collection of nodes (RoadNode) and ways (RoadWay) where a node is a point in the scene, and a way contains an ordered list of nodes. The top of a way is the start node, and the bottom is the end node. The way represents a direction of travel (towards the end node) for Vehicles. RoadNodes can be marked as Start Node to allow vehicles to spawn on that node. Please note that the option Start Node is different to "start node" and focuses on spawning vehicles, but a "start node" normally represents the first node of a way.

Multiple ways can use the same RoadNode to attach roads together. For example a node is the last node in Way1 but is the first node in Way2. Vehicles would then be able to drive across from Way1 to Way2.

A Vehicle Path represents a route that a vehicle drives along. Vehicle paths are created with the A* path finding algorithm, using all ways in the scene.

Vehicle Paths

Vehicle Paths are used by vehicles to reach their destination. They are created from the Road Network of RoadNodes and RoadWays for a specific vehicle.

Creating a Path

Each node represents a point along the path. The vehicle will follow from node1 (the spawn point) to the last node which in this case is node5 where the vehicle will be destroyed. If there is a traffic light on the path, a node (also known as a stop node) will have to be placed at the traffic light which can be easily done by either moving an existing RoadNode or creating a new one by copying and pasting a node and moving that node to the correct location (make sure the nodes are still in the correct order on the RoadWay). Once the stop node is in the right position, assign the RoadNode to the related traffic light's Stop Nodes. This node will be where the vehicle stops for that traffic light. Stop Lines can also be used to control the traffic where Traffic Lights are not used. Make sure that all paths are above ground but not too high so first node can spawn the vehicle.

To measure density, attach the DensityMeasurementPoint script to a RoadNode game object which is normally positioned after a junction. Once the script is attached, a collider with Is Trigger checked needs to also be attached to the node game object which should be big enough to detect vehicles passing through.

Stop Lines

Stop Lines can be assigned to a RoadNode by attaching the StopLine script to the game object to allow vehicles to evaluate whether the road ahead is safe to continue. Intersections (intersections between the current Vehicle Path and different Vehicle Paths) are evaluated to check whether approaching vehicles are a danger to the waiting vehicle. The waiting vehicle will then continue once safe to do so.

There are currently two different types of StopLine:

  • MERGE - the waiting vehicle will check all approaching vehicles, used when merging into another road.
  • JUNCTION - the waiting vehicle will only check approaching vehicles to the right when driving on the left, and the left when driving on the right. Used in Junctions without Traffic Lights.

Find out how stop lines effect a vehicle's behaviour here.

Junctions

Junctions are a collection of traffic lights and pedestrian crossings which are controlled by set states. For example, in:

  • Junction State 1 - Traffic Light A is Green, Traffic Light B is Red, Pedestrian Crossing C is disallowing crossings.
  • Junction State 2 - Traffic Light A is Red, Traffic Light B is Green, Pedestrian Crossing C is disallowing crossings.
  • Junction State 3 - Traffic Light A is Red, Traffic Light B is Red, Pedestrian Crossing C is allowing crossings.

A junction will be in only one state at a time and will change states when needed via the AI program or built-in demo. The Junction script has the following fields:

  • Junction ID – A unique ID to identify the junction from others.
  • Junction Camera – The camera which is assigned to the junction and is used for the AI script to set an action which is changing the Junction State.

Junction States

Junction States are Game Objects assigned to the parent Game Object with the Junction Script attached.

Junction States Configuration

The Junction State script has the following fields:

  • State Number – The number of the state which is unique to the Junction to identify the other states.
  • Traffic Light States (List) – A list of the different traffic lights within the junction that need to change on this current state.
    • Traffic Light Id – The traffic light ID to change.
    • Light Colour – The colour for the traffic light to change to.
  • Pedestrian Crossing States (List) – A list of the different Pedestrian Crossings within the junction that needs to change on the current state.
    • Pedestrian Crossing Id – The pedestrian crossing ID to change.
    • Allow Crossing – A Boolean which if checked will allow a pedestrian to cross on the selected pedestrian crossing during the state.

Note: Any Traffic Lights or Crossings that are missing off the list will stay in the same state.

Environment Settings

With Environment Settings, rain, snow, and night can be toggled, different lighting can be set, and surface friction can be changed too.

Environment Settings Configuration

The Environment Settings script has the following fields:

  • Rain – A Boolean to toggle Rain on and off.
  • Snow – A Boolean to toggle Snow on and off.
  • Night – A Boolean to toggle Night on and off.
  • Ambient Intensity – The current lighting intensity of the scene.
  • Rain Sky Box – The sky box to be used when Rain is toggled.
  • Snow Sky Box – The sky box to be used when Snow is toggled (overrides rain sky box when rain and snow is toggled).
  • Night Sky Box – The sky box to be used when Night is toggled (overrides rain and / or snow sky box when both or each of them are toggled with night being toggled too).
  • Main Light – The main light within the scene.
  • Night Light Colour – The colour of the main light when night has been toggled.
  • Normal Surface Material – The physics material used as default.
  • Rain Surface Material – The physics material to be used when raining.
  • Snow Surface Material – The physics material to be used when snowing.

The physics material can be found in /Assets/Resources/Materials/PhysicMaterials and friction values can be changed within those objects.

Python manager

The PythonManager class controls the connection between the AI Python script and Traffic3D. A loop is created to train the AI. First the manager takes screenshots using all the junction cameras in the scene. The screenshots are sent to the Python script for it to process, once processed the Python script sends the actions back for each Junction in the scene, this action is the junction state number that the junction needs to change to. Density and Flow is then calculated and outputted in the /Assets/Results/ folder. Rewards are then sent to the Python script for the script to process. See the model generator page to learn more about the Python script. The Python manager also controls the frame-rate for the scene.

PythonManager has the following fields:

  • Frame Rate - when the frame rate is lower, simulation time will run faster. See the Unity API documentation for more information.

Sumo Manager

This manages the connection between SUMO and Traffic3D and allows different software to control different features. Click here learn more about SUMO and how to connect to SUMO.

Sumo Manager Configuration

The Sumo Manager Script has the following fields:

  • Ip – The IP address of the SUMO instance
  • Port – The port of the SUMO instance
  • Sumo Control Settings (List) – A list of the different control points that can be controlled by either Traffic3D or SUMO
    • Sumo Link Control Point – The setting to control.
    • Controlled by Sumo – A Boolean which if true means that the above setting is controlled with SUMO

Real time graphs

Graphs display on screen with real-time data about the simulation. These can be toggled at the start and in mid simulation. Currently there are three graphs:

  • Time-Travelled – The amount of time it has taken a vehicle to travel the full distance of the journey.
  • Throughput – The number of vehicles that has completed the journey during a single simulation time step.
  • Delay – The amount of time it has taken for a vehicle to pass a junction.

The Graph Manager script has a Boolean field for each of the graphs above to toggle them on and off.

Camera Manager

This object takes the screenshots for the Python script and is required to be attached to all junction cameras.