Class VehicleInputHandler
Single point every vehicle system reads input from, whatever the source: Input Manager, Input System, mobile touch or a custom provider. Handles smoothing, the modification callbacks, and the manual override path used by AI and network code.
Inherited Members
Namespace: NWH.VehiclePhysics2.Input
Assembly: NWH.VehiclePhysics2.dll
Syntax
[Serializable]
public class VehicleInputHandler : VehicleComponent
Remarks
Providers are found in the scene and every active, enabled one is polled, so keyboard, gamepad and touch can be used interchangeably during a session.
Fields
autoSetInput
When enabled, retrieves input from the InputProviders in the scene. Disable to set input through external scripts, such as an AI controller.
Declaration
[FormerlySerializedAs("autoSettable")]
[Tooltip(" When enabled input will be auto-retrieved from the InputProviders present in the scene.\r\n Disable to manually set the input through external scripts, i.e. AI controller.")]
public bool autoSetInput
Field Value
| Type | Description |
|---|---|
| bool |
brakeDeadzone
Fraction of brake travel ignored before input registers. Remaining range is rescaled.
Declaration
[Range(0, 0.5)]
[Tooltip("Fraction of brake travel ignored before input registers. Remaining range is rescaled. 0 = disabled.")]
public float brakeDeadzone
Field Value
| Type | Description |
|---|---|
| float |
inputModifyCallback
Callback for modifying input values after they are retrieved from the InputProviders.
Declaration
[Tooltip("Used to modify the input values.\r\nCalled after the input values are retrieved from the InputProviders.")]
public UnityEvent inputModifyCallback
Field Value
| Type | Description |
|---|---|
| UnityEvent |
states
Processed input for this frame, after smoothing and the modification callbacks. Every vehicle system reads from here rather than from the providers.
Declaration
[Tooltip("All the input states of the vehicle. Can be used to set input through scripting or copy the inputs\r\nover from other vehicle, such as truck to trailer.")]
[NonSerialized]
public VehicleInputStates states
Field Value
| Type | Description |
|---|---|
| VehicleInputStates |
Remarks
With autoSetInput off, write these fields directly to drive the vehicle from an AI controller, a trailer sync or a replay.
steeringDirectionChangeMultiplier
Multiplier for return speed when changing steering direction. Higher = faster direction changes.
Declaration
[Range(1, 5)]
[Tooltip("Speed multiplier when changing direction (left to right). Higher = snappier direction changes.")]
public float steeringDirectionChangeMultiplier
Field Value
| Type | Description |
|---|---|
| float |
steeringReturnTime
Time in seconds for steering to return to center when released.
Declaration
[Range(0, 0.5)]
[Tooltip("Time for steering to return to center.")]
public float steeringReturnTime
Field Value
| Type | Description |
|---|---|
| float |
steeringSmoothingTime
Time in seconds to reach full steering input. Smooths binary keyboard input. Set to 0 to disable.
Declaration
[Range(0, 0.5)]
[Tooltip("Time to reach full steering from zero. 0 = disabled. Recommended: 0.15-0.25s for keyboard.")]
public float steeringSmoothingTime
Field Value
| Type | Description |
|---|---|
| float |
swapInputInReverse
Swaps the throttle and brake axes while in reverse, so the throttle moves the vehicle backwards and the brake slows it down. Turn it off for a sim where the pedals stay mapped to throttle and brake regardless of gear.
Declaration
[ShowInSettings("Swap Input In R")]
[Tooltip("Swaps throttle and brake axes when vehicle is in reverse.")]
public bool swapInputInReverse
Field Value
| Type | Description |
|---|---|
| bool |
throttleDeadzone
Fraction of throttle travel ignored before input registers. Remaining range is rescaled.
Declaration
[Range(0, 0.5)]
[Tooltip("Fraction of throttle travel ignored before input registers. Remaining range is rescaled. 0 = disabled.")]
public float throttleDeadzone
Field Value
| Type | Description |
|---|---|
| float |
Properties
Boost
Boost button state. True while the boost button is held down.
Declaration
public bool Boost { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Brakes
Brake axis. For combined throttle/brake input use 'Vertical' instead.
Declaration
public float Brakes { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
Clutch
Clutch axis.
Declaration
public float Clutch { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
CruiseControl
Cruise control toggle state. True when the button was pressed this frame.
Declaration
public bool CruiseControl { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
EngineStartStop
Engine start/stop toggle state. True when the button was pressed this frame.
Declaration
public bool EngineStartStop { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
ExtraLights
Extra lights (fog lights, work lights) toggle state. True when the button was pressed this frame.
Declaration
public bool ExtraLights { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
FlipOver
Flip-over request flag. True when the button was pressed this frame.
Declaration
public bool FlipOver { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Handbrake
Handbrake axis. Value is automatically clamped to [0, 1] range.
Declaration
public float Handbrake { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
HazardLights
Hazard lights toggle state. True when the button was pressed this frame.
Declaration
public bool HazardLights { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
HighBeamLights
High beam headlights toggle state. True when the button was pressed this frame.
Declaration
public bool HighBeamLights { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Horn
Horn button state. True while the horn button is held down.
Declaration
public bool Horn { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
InputSwappedBrakes
Returns throttle or brake input based on 'swapInputInReverse' setting and current gear. If swapInputInReverse is true, throttle will act as brake and vice versa while driving in reverse.
Declaration
public float InputSwappedBrakes { get; }
Property Value
| Type | Description |
|---|---|
| float |
InputSwappedThrottle
Returns throttle or brake input based on 'swapInputInReverse' setting and current gear. If swapInputInReverse is true, brake will act as throttle and vice versa while driving in reverse.
Declaration
public float InputSwappedThrottle { get; }
Property Value
| Type | Description |
|---|---|
| float |
IsInputSwapped
True when throttle and brake axis are swapped.
Declaration
public bool IsInputSwapped { get; }
Property Value
| Type | Description |
|---|---|
| bool |
LeftBlinker
Left turn signal toggle state. True when the button was pressed this frame.
Declaration
public bool LeftBlinker { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
LowBeamLights
Low beam headlights toggle state. True when the button was pressed this frame.
Declaration
public bool LowBeamLights { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
RightBlinker
Right turn signal toggle state. True when the button was pressed this frame.
Declaration
public bool RightBlinker { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
ShiftDown
Sequential shift down flag. True when the button was pressed this frame.
Declaration
public bool ShiftDown { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
ShiftInto
Direct gear selection for H-pattern shifters. NO_SHIFT indicates no gear selected.
Declaration
public int ShiftInto { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
ShiftUp
Sequential shift up flag. True when the button was pressed this frame.
Declaration
public bool ShiftUp { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Steering
Steering axis.
Declaration
public float Steering { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
Throttle
Throttle axis. For combined throttle/brake input, use 'Vertical' instead.
Declaration
public float Throttle { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
TrailerAttachDetach
Trailer attach/detach toggle state. True when the button was pressed this frame.
Declaration
public bool TrailerAttachDetach { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Vertical
Throttle and brakes on one axis: positive sets throttle, negative sets brakes. Use the Throttle and Brakes axes to drive them separately.
Declaration
public float Vertical { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
Methods
CombinedInputGear<T>(Func<T, int>)
Highest gear selected across all active providers of the given type.
Declaration
public static int CombinedInputGear<T>(Func<T, int> selector) where T : InputProvider
Parameters
| Type | Name | Description |
|---|---|---|
| Func<T, int> | selector | Function to extract gear value from the input provider. |
Returns
| Type | Description |
|---|---|
| int | Highest gear index from all providers, or VehicleInputStates.NO_SHIFT if no gear is selected. |
Type Parameters
| Name | Description |
|---|---|
| T | Type of input provider to query. |
HandleAutomaticInputAvailabilityChanged(bool)
Resets only states retrieved from scene-wide automatic input. Manual input paths are unaffected because the caller gates this method on autoSetInput.
Declaration
public void HandleAutomaticInputAvailabilityChanged(bool isAvailable)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | isAvailable |
ResetAutomaticInput()
Clears controls sourced from shared automatic input, including the steering filter's retained state. Manual/network/trailer input paths are not expected to call this method.
Declaration
public void ResetAutomaticInput()
ResetShiftFlags()
Clears the shift flags once a shift has been processed, so one press cannot shift twice.
Declaration
public void ResetShiftFlags()
VC_Disable(bool)
Disables the component and stops its updates.
Declaration
public override bool VC_Disable(bool calledByParent)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | calledByParent | True when called by a parent ManagerVehicleComponent fan-out or the VehicleController enable/disable loop. The LOD system passes false. |
Returns
| Type | Description |
|---|---|
| bool | True if successfully disabled, false otherwise |
Overrides
Remarks
Refused on a component that is not initialized. Records whether the call came from a parent, which is what VC_Enable checks before a bulk re-enable.
VC_Initialize()
One-time setup, once per vehicle startup and after the VehicleController reference is set. Sets state.initialized on completion; an override that fails must leave it false.
Declaration
protected override void VC_Initialize()
Overrides
VC_Update(float)
Per-frame update for input, visuals and UI. Only called while the component is active. Physics belongs in VC_FixedUpdate, not here.
Declaration
public override void VC_Update(float DeltaTime)
Parameters
| Type | Name | Description |
|---|---|---|
| float | DeltaTime | Time elapsed since last Update in seconds |