Skip to main content

Class VehicleTrafficBehavior

Extends TrafficBehaviour with vehicle-specific process dispatch (Car vs Pedestrian vs Stopline layers) and dynamically steers sensors toward the next waypoint so that detection stays aligned with the vehicle's intended path on curved roads.

public class VehicleTrafficBehavior : TrafficBehaviour

Inheritance​

Inherited Members​

Remarks​

The base class drives sensors as fixed frustums. For vehicles following waypoint paths, a stationary sensor aimed at the car's current facing can miss objects around a bend. DoUpdate overrides the base to rotate the search and gap-keeping sensors to face the next WaypointProgressTracker target each frame, keeping detection predictive rather than reactive.

Gap-keeping sensor radius is also narrowed proportionally to the turn angle so that the lateral spread of the arc does not detect vehicles in adjacent lanes during sharp turns.

Methods​

DoUpdate()​

Advances all active processes by one tick and removes any that have completed.

public override void DoUpdate()

Remarks​

Marked virtual and public so the BT (AIBrainComponent) can call it explicitly when IsHijacked suppresses the Unity Update loop.

TryGetProcess(GameObject, out TrafficProcess, out ProcessData, out ContactStruct)​

Maps otherObject to the correct TrafficProcess subclass and populates its ProcessData, using the object's layer to distinguish vehicles from pedestrians.

protected override bool TryGetProcess(GameObject otherObject, out TrafficProcess process, out TrafficProcess.ProcessData processData, out TrafficBehaviour.ContactStruct currentContactValueParameter)

Parameters​

NameTypeDescription
otherObjectGameObjectThe detected object.
processTrafficProcessReceives the newly created process instance.
processDataTrafficProcess.ProcessDataReceives the process initialisation data.
currentContactValueParameterTrafficBehaviour.ContactStructReceives the contact thresholds for this interaction.

Returns​

bool — true if a process was created; false if the object should be ignored.

Remarks​

The base implementation differentiates on the "Mine" layer (pedestrians/player) versus all other layers (vehicles). Subclasses override this to add vehicle-type-specific logic (e.g., checking relative speed before spawning a braking process).

  • Remarks
  • Methods
    • DoUpdate()
    • TryGetProcess(GameObject, out TrafficProcess, out ProcessData, out ContactStruct)