Class SpeedLimiterModule
Module that enforces a maximum speed limit by controlling engine power output.
Inherited Members
Namespace: NWH.VehiclePhysics2.Modules.SpeedLimiter
Assembly: NWH.VehiclePhysics2.dll
Syntax
[Serializable]
public class SpeedLimiterModule : VehicleComponent
Remarks
The SpeedLimiterModule prevents vehicles from exceeding a configured speed limit by reducing engine power to zero when the limit is reached. Unlike braking systems, this module does not apply braking force - it simply prevents further acceleration by cutting throttle authority.
How It Works: - Registers a power modifier callback with the engine - When speed exceeds the limit, returns 0 (no power) - When speed is below the limit, returns 1 (full power) - Works by multiplying the engine's power output
Use Cases: - Speed-restricted vehicles (delivery trucks, buses, construction vehicles) - Racing games with different vehicle classes and regulations - Gameplay mechanics requiring speed caps (school zones, restricted areas) - AI vehicle behavior control - Tutorial or difficulty progression systems
Behavior Notes: - Does not apply brakes - the vehicle will coast down naturally due to drag - Will not prevent downhill acceleration from gravity - Works in both forward and reverse directions (uses absolute speed) - Can be enabled/disabled at runtime for dynamic speed restrictions
Fields
active
Indicates whether the speed limiter is currently limiting power.
Declaration
public bool active
Field Value
| Type | Description |
|---|---|
| bool |
Remarks
True when the vehicle speed exceeds the limit and power is being cut. False when the vehicle is below the speed limit.
This is a read-only status field useful for: - UI indicators showing limiter activation - Visual effects (warning lights, dashboard indicators) - Audio cues when limit is reached - Analytics or telemetry systems
speedLimit
Maximum allowed speed before the limiter cuts engine power.
Declaration
[Tooltip("Speed limit above which the throttle will be cut.")]
public float speedLimit
Field Value
| Type | Description |
|---|---|
| float |
Remarks
The numeric value is interpreted according to speedUnits. When vehicle speed exceeds this value, throttle authority is removed.
Typical values by vehicle type (in km/h): - Delivery vans: 90-110 - Buses: 80-100 - Construction vehicles: 40-60 - Racing regulations: varies by class
Set to 0 to disable speed limiting completely.
speedUnits
Unit of measurement for the speedLimit value.
Declaration
[Tooltip("Units which will be used for speed limiter. Defaults to m/s.")]
public SpeedLimiterModule.SpeedUnits speedUnits
Field Value
| Type | Description |
|---|---|
| SpeedLimiterModule.SpeedUnits |
Remarks
Specifies how to interpret the speed limit value: - ms: Meters per second (Unity native) - kmh: Kilometers per hour (most common) - mph: Miles per hour (US/UK)
The module automatically converts the specified unit to m/s internally. Choose the unit most familiar to your design team to avoid conversion errors.
Methods
SpeedPowerLimiter(float)
Power modifier callback that restricts engine power when speed limit is exceeded.
Declaration
public float SpeedPowerLimiter(float DeltaTime)
Parameters
| Type | Name | Description |
|---|---|---|
| float | DeltaTime | Time step for the current frame (unused in this modifier). |
Returns
| Type | Description |
|---|---|
| float | Power multiplier: 1.0 (full power) when below limit, 0.0 (no power) when at or above limit. |
Remarks
This method is registered as an engine power modifier and called each physics frame. It compares the current vehicle speed against the configured limit and returns a multiplier that is applied to the engine's power output.
Return values: - 1.0: Normal operation, speed is below limit - full power available - 0.0: Speed limit exceeded - no power, throttle input is ignored
The method converts the configured speed limit to m/s based on speedUnits for comparison with the vehicle's speed. This conversion happens every frame to support runtime changes to the speed limit or units.
VC_Disable(bool)
Disables the component and stops updates. Override to add component-specific disable logic.
Declaration
public override bool VC_Disable(bool calledByParent)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | calledByParent | True if called by parent component or LOD system |
Returns
| Type | Description |
|---|---|
| bool | True if successfully disabled, false otherwise |
Overrides
Remarks
Component must be initialized before it can be disabled. Tracks whether disable was called by parent to manage LOD system interaction.
VC_Enable(bool)
Enables the component and starts updates. Override to add component-specific enable logic.
Declaration
public override bool VC_Enable(bool calledByParent)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | calledByParent | True if called by parent component or LOD system |
Returns
| Type | Description |
|---|---|
| bool | True if successfully enabled, false otherwise |
Overrides
Remarks
Will initialize the component if not already initialized. Components disabled by LOD system will track the parent caller to prevent manual enabling while LOD is controlling state.