Traffic Car

How To Create

  1. Create a vehicle using the Car Prefab Creator tool (for example Simple physics entity type).

    _images/Step1.png

    Car Prefab Creator final step example.

  2. Make sure, that the vehicle collection contains vehicle you have created.

    _images/Step2.png
  3. Make sure, that the preset contains the vehicle.

    _images/Step3.png
  4. Open the Traffic settings and select the Simple physics entity type (if you have created a Simple physics entity).

    _images/Step4.png
  5. Open the Hub object in the scene and press the Copy To Subscene button.

    _images/Step5.png
  6. Open the EntitySubScene, find the TrafficCarEntityPoolBakerRef gameobject, make sure the correct preset is assigned.

    _images/Step6.png
  7. Adjust the traffic settings of the created vehicles.

Vehicle Physics Types

Custom Physics

Authoring components

Vehicle Authoring
_images/vehicleAuthoring.png
Wheel
_images/wheel.png
Wheel mass : wheel mass.
Max steering angle : max steering angle of the steering wheel in degrees.
Power steering : rate of steering improvement.
Custom steering limit : limiting steering angle based on vehicle speed (Y-axis rate value (1 - max steering angle), X-axis speed in metres per second).
Radius : wheel radius.
Width : wheel width.
Apply impulse offset : applying force offset relative to lower point of wheel (without offsetting the force applied to the lower point of the wheel).
Cast type:
  • Ray : raycast by ray.

  • Collider : raycast by collider (collider size based on wheel radius and width).

Cast layer : physical layer that collides with the wheel.
Suspension
_images/suspension.png
Suspension length : length of suspension.
Stiffness : spring stiffness of suspension.
Damping : force to return spring to its original length.
Friction
_images/friction1.png
Longitudinal : forward friction curve (Y-axis - forward slip value, X-axis forward speed in metres per second).
Lateral : lateral friction curve (Y-axis - lateral slip value, X-axis lateral speed in metres per second).
Forward friction : forward friction value.
Lateral friction : lateral friction value.
Brake friction : brake friction value.
Drag : drag value of the vehicle.
Transient Forces
_images/transientForce.png

Transient force is required to hold the car on an inclined ramp during manual braking.

Use forward transient force : on/off forward transient force.
Min transient forward speed : min forward speed when transient force is applied.
Max forward friction rate : max friction for transient force calculated by multiplying the entered rate by the forward friction.
Forward relax multiplier : step of forward force increase per frame.
Use lateral transient force : on/off lateral transient force.
Min transient lateral speed : min lateral speed when transient force is applied.
Max lateral friction rate : max friction for transient force calculated by multiplying the entered rate by the lateral friction.
Lateral relax multiplier : step of lateral force increase per frame.
Brakes
_images/brakes.png
Brake torque : torque of brake.
Handbrake torque : torque of handbrake.
Engine
_images/engine1.png
Torque : engine torque.
Transimission rate : engine torque to wheel speed ratio.
Scene Settings
_images/sceneSettings.png
Show debug : on/off debugging for wheel and suspension at runtime (VehicleCustomDebugger).
Show suspension origin : on/off display of suspension origin.
Show suspension : on/off display of suspension.
Origin move:
  • Disabled : disabled handle.

  • Wheel : on/off handle for wheel origin.

  • Suspension origin : on/off handle for suspension origin.

  • Suspension : on/off handle for suspension and wheel origin.

Template Settings
_images/templateSettings.png
Tabs:
  • Create new : create new template settings.

  • Copy from template : copy settings from the selected template.

  • Save to template : save settings to the selected template.

Copy settings type:
  • Physics settings : copy the physics settings (mass, damping, gravity) of the PhysicsBody component.

  • Center of mass : copy the center of mass local position of the PhysicsBody component.

  • Offsets : copy the local offset of the wheels.

  • Settings : copy the settings of the VehicleAuthoring component.

Wheel Refs
_images/wheelRefs.png
Wheel : reference to wheel.
Driving : on/off driving force for the wheel.
Brake : on/off braking force for the wheel.
Brake rate : brake rate.
Handbrake rate : handbrake rate.
PhysicsBody
_images/physicsBody.png
PhysicsShape
_images/physicsShape.png

Example

Simple Physics

Authoring components

CarWheelAuthoring
_images/CarWheelAuthoring.png
Wheel base : wheel radius.
All wheels : all wheels of the vehicle.
Steering wheels : wheels that can turn.
PhysicsBody
_images/PhysicsBody.png
PhysicsShape
_images/physicsShape1.png

Example

Optional components if the car moves with physics.

No Physics

Common Authoring Components

TrafficCarEntityAuthoring

_images/TrafficCarEntityAuthoring.png

Main component of traffic entity [required].

Hull mesh renderer : vehicle hull mesh renderer reference.
Physics shape : vehicle entity PhysicsShape reference.
Faction type : selected faction type of vehicle.
Car type : selected car type of vehicle.
Bounds source type : selected bounds source for the entity bounds.
Traffic group : selected traffic group.

Shared Settings

Each vehicle has a common set of settings that are described here

CarSoundAuthoring

_images/CarSoundAuthoring.png

Component for vehicle sounds [optional].

HealthAuthoring

Vehicle health component for damage system [optional].

CarDamageEngineAuthoring

Component for visual presentation of damage in the damage systems [optional].

PlayerTargetAuthoring

Component for player targeting systems [optional].

CullState Info

States

Parking

Сar parking consists of the following states:

Entering parking states

  1. The car has chosen the path containing the parking node.

  2. The car links the parking node to prevent it from being selected by other cars (the list of linked nodes can be customized here).

  3. 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).

  4. Stopping the engine state is starting (if enabled in the stopping engine config & vehicle in view of camera’s player).

  5. Pedestrian gets out of the car.

Exiting parking states

  1. The Pedestrian enters the pedestrian parking node, if available.

  2. The parking car removes link with TrafficNode.

  3. Ignition state system starts (if enabled in ignition config).

  4. Once the car has started the engine, the car starts moving.

Avoidance

Avoidance is used in the case of stuck vehicles.
Currently enabled in the following situations:
_images/AvoidanceExample1.png

Cyclical obstacle example.

_images/AvoidanceExample2.png

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

TrafficCarRaycastConfig.

Debugger

TrafficCarRaycastDebugger.

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);