Class MetricsModule
Vehicle telemetry and statistics tracking module.
Inherited Members
Namespace: NWH.VehiclePhysics2.Modules.Metrics
Assembly: NWH.VehiclePhysics2.dll
Syntax
[Serializable]
public class MetricsModule : VehicleComponent
Remarks
The MetricsModule continuously records various vehicle performance metrics and driving statistics. It tracks both cumulative values (like total distance traveled) and peak values (like top speed achieved). All metrics are updated in real-time during gameplay and can be accessed for display purposes, achievements, or gameplay mechanics.
Key features: - Distance tracking (odometer) for total vehicle mileage - Speed records including top speed and average speed - Drift metrics for both continuous and total drift time/distance - Automatic drift detection based on lateral wheel slip - Configurable drift timeout for continuous drift tracking
Common use cases: - Dashboard displays and HUD elements - Achievement/trophy systems (e.g., "Drift for 10 seconds") - Gameplay mechanics (e.g., boost systems based on drift distance) - Statistics screens and player progression tracking - Replay systems and performance analysis
All metrics are automatically reset when the module is disabled and re-enabled, except when persistence is implemented through external save systems.
Fields
averageSpeed
Average speed calculated since the module was enabled (m/s).
Declaration
public MetricsModule.Metric averageSpeed
Field Value
| Type | Description |
|---|---|
| MetricsModule.Metric |
Remarks
Calculated as total distance traveled divided by time elapsed. Useful for fuel economy calculations and driving style analysis. Reset when the module is re-enabled.
continousDriftDistance
Distance covered during the current continuous drift (meters).
Declaration
public MetricsModule.Metric continousDriftDistance
Field Value
| Type | Description |
|---|---|
| MetricsModule.Metric |
Remarks
Tracks distance while any wheel is experiencing lateral slip. Resets to zero when drift ends (after timeout period).
Use for: - Drift scoring systems - Combo multipliers - Visual feedback intensity
NOTE: Variable name contains typo ("continous" vs "continuous") but cannot be renamed without breaking serialization compatibility.
continousDriftTime
Duration of the current continuous drift (seconds).
Declaration
public MetricsModule.Metric continousDriftTime
Field Value
| Type | Description |
|---|---|
| MetricsModule.Metric |
Remarks
Tracks time while any wheel is experiencing lateral slip. Includes a timeout period (default 0.75s) to allow for brief grip recovery without breaking the drift chain.
Use for: - Drift duration achievements - Skill-based scoring - Drift combo systems
NOTE: Variable name contains typo ("continous" vs "continuous") but cannot be renamed without breaking serialization compatibility.
odometer
Total distance traveled by the vehicle (meters).
Declaration
public MetricsModule.Metric odometer
Field Value
| Type | Description |
|---|---|
| MetricsModule.Metric |
Remarks
Cumulative distance counter that continuously increments while the vehicle moves. Persists until manually reset or module is re-enabled.
Use for: - Vehicle mileage tracking - Service interval calculations - Distance-based achievements - Wear and tear simulation
topSpeed
Maximum speed achieved since module was enabled (m/s).
Declaration
public MetricsModule.Metric topSpeed
Field Value
| Type | Description |
|---|---|
| MetricsModule.Metric |
Remarks
Records the highest instantaneous speed reached. Only updates when current speed exceeds the stored value.
Use for: - Speed records and leaderboards - Achievement tracking - Performance testing
totalDriftDistance
Total accumulated drift distance across all drifts (meters).
Declaration
public MetricsModule.Metric totalDriftDistance
Field Value
| Type | Description |
|---|---|
| MetricsModule.Metric |
Remarks
Cumulative counter of all distance covered while drifting. Unlike continuous drift distance, this never resets during gameplay. Useful for lifetime statistics and progression systems.
totalDriftTime
Total accumulated drift time across all drifts (seconds).
Declaration
public MetricsModule.Metric totalDriftTime
Field Value
| Type | Description |
|---|---|
| MetricsModule.Metric |
Remarks
Cumulative counter of all time spent drifting. Unlike continuous drift time, this never resets during gameplay. Useful for lifetime statistics and career progression.
Methods
VC_Update(float)
Updates all tracked metrics based on current vehicle state.
Declaration
public override void VC_Update(float DeltaTime)
Parameters
| Type | Name | Description |
|---|---|---|
| float | DeltaTime | Time since last update in seconds. |
Overrides
Remarks
Called every frame when the module is enabled. Updates the following metrics:
- Odometer: Accumulates distance traveled - Top Speed: Records maximum speed achieved - Average Speed: Calculates mean speed from total distance and time - Drift Metrics: Tracks continuous and total drift time/distance
Drift detection uses lateral wheel slip (skidding) as the trigger condition. The continuous drift counters maintain their values during brief grip recoveries within the timeout period, allowing for realistic drift chains.