Traffic Car
How To Create
Create a vehicle using the Car Prefab Creator tool (for example Simple physics entity type).
Car Prefab Creator final step example.
Make sure, that the vehicle collection contains vehicle you have created.
Make sure, that the preset contains the vehicle.
Open the Traffic settings and select the Simple physics entity type (if you have created a Simple physics entity).
Open the Hub object in the scene and press the Copy To Subscene button.
Open the EntitySubScene, find the TrafficCarEntityPoolBakerRef gameobject, make sure the correct preset is assigned.
- Adjust the traffic settings of the created vehicles.
For simple physics.
For custom physics.
Vehicle Physics Types
Custom Physics
Entities that are moved by the custom physical system.
Hybrid Entity Custom Physics & Pure Entity Custom Physics types refer to this.
Simple Physics
Entities moved by the simple physical system (by simply adding the physics velocity to the physics body).
Hybrid entity simple physics & Pure entity simple physics types refer to this.
Authoring components
PhysicsBody
PhysicsShape
Example
Optional components if the car moves with physics.
No Physics
Pure entities that moved by transform system without physics.
Contains the same components as Simple Physics.
Pure entity no physics type refer to this.
CullState Info
States
Culled : entity is destroyed.
- CloseToCamera:
Cull physics (if enabled) : custom physics & simple physics temporarily converted to no physics entity.
Cull wheel (if enabled) : disabling wheel rotating.
InVisionOfCamera : entity fully enabled.
Parking
Сar parking consists of the following states:
Entering parking states
The car has chosen the path containing the parking node.
The car links the parking node to prevent it from being selected by other cars (the list of linked nodes can be customized here).
When the car reaches the parking node, the car position correction is activated for precise parking (if disabled in the parking config, this step is skipped).
Stopping the engine state is starting (if enabled in the stopping engine config & vehicle in view of camera’s player).
Pedestrian gets out of the car.
Exiting parking states
The Pedestrian enters the pedestrian parking node, if available.
The parking car removes link with TrafficNode.
Ignition state system starts (if enabled in ignition config).
Once the car has started the engine, the car starts moving.
Avoidance
- Currently enabled in the following situations:
A cyclical obstacle where cars get stuck in each other (avoidance config).
A car has collided frontally with another car (collision config).
Cyclical obstacle example.
Avoiding cyclical obstacle example.
Note
Test scene example.
Rail Movement
The Rail movement is used to drive the vehicle precisely along the path, which can be useful in small enclosed parking areas, for example. To enable rail movement, tick on the Rail parameter in the path settings. Open the rail config to adjust the Rail parameters.
Note
Enabled by default for trams.
Obstacle Detection
Raycast
Config
Debugger
Modes
Hybrid mode : raycast is activated only when the selected targets are close to the car.
Raycast only : raycasts are sent constantly.
To define raycast targets for Hybrid or Raycast only modes, redefine the GetTargetQuery method in the TrafficCarRaycastObstacleTargetQueryProvider
class, which returns the EntityQuery of the targets.
public static EntityQuery GetTargetQuery(
SystemBase sourceSystem,
TrafficCarDetectObstacleMode trafficCarDetectObstacleMode,
TrafficCarDetectNpcMode trafficCarDetectNpcMode,
out CollisionFilter tempRaycastCollisionFilter,
out CollisionFilter raycastAlwaysCollisionFilter);
Hybrid Mode Filter : collision filter of hybrid raycast mode.
Raycast Only Filter : collision filter of raycast only mode.
Note
You can also dynamically change the raycast target for Hybrid mode by adding or removing the TrafficCustomRaycastTargetTag component.
Layer constants are stored in the ProjectConstants.cs file.