NWH Vehicle Physics 2
Search Results for

    Show / Hide Table of Contents

    Class VehicleInputHandler

    Central input management system that handles vehicle control inputs from various sources including keyboard/mouse, gamepad, mobile touch, and custom input providers.

    Inheritance
    object
    VehicleComponent
    VehicleInputHandler
    Inherited Members
    VehicleComponent.state
    VehicleComponent.vehicleController
    VehicleComponent.IsActive
    VehicleComponent.VC_Initialize(VehicleController)
    VehicleComponent.VC_FixedUpdate(float)
    VehicleComponent.VC_SetDefaults()
    VehicleComponent.VC_LoadStateFromStateSettings()
    VehicleComponent.VC_Enable(bool)
    VehicleComponent.VC_DrawGizmos()
    VehicleComponent.VC_Validate(VehicleController)
    VehicleComponent.UpdateLOD()
    VehicleComponent.ToggleState()
    Namespace: NWH.VehiclePhysics2.Input
    Assembly: NWH.VehiclePhysics2.dll
    Syntax
    [Serializable]
    public class VehicleInputHandler : VehicleComponent
    Remarks

    The VehicleInputHandler acts as an intermediary between input sources and vehicle systems, providing a unified interface for vehicle control regardless of the input method used. It supports multiple input providers simultaneously and can blend inputs from different sources.

    Key features include: - Support for multiple input systems: Unity Input Manager, Unity Input System, Mobile, and custom providers - Automatic input provider detection and management - Input smoothing and filtering for improved vehicle control - Manual input override for AI controllers and external scripts - Input modification callbacks for custom input processing - Real-time input state monitoring and debugging

    The system automatically detects available input providers in the scene and uses the highest priority provider that is currently active, allowing switching between keyboard, gamepad, or touch during gameplay, such as from keyboard to gamepad or mobile touch controls.

    Fields

    autoSetInput

    When enabled input will be auto-retrieved from the InputProviders present in the scene. Disable to manually set the input through external scripts, i.e. 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

    Used to modify the input values. Called after the input values 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

    Current state of all vehicle input values including throttle, brakes, steering, and auxiliary inputs. Each input is normalized to 0-1 range for analog inputs, and 0 or 1 for digital inputs.

    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

    This structure contains all processed input values after smoothing and modification callbacks. Can be used to manually override inputs through scripting for AI controllers, trailer synchronization, or replay systems. When autoSetInput is false, populate these values directly to control the vehicle. All vehicle systems read from these states rather than directly from input providers.

    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 throttle and brake axes when vehicle is in reverse gear for intuitive reverse driving. When enabled, pressing the throttle input will brake when reversing, and brake input will accelerate backward.

    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
    Remarks

    This feature makes reverse driving more intuitive by matching player expectations: - Throttle input = move backward when in reverse - Brake input = slow down/stop when reversing

    Most players expect "forward" input to mean "move in the selected direction" rather than always move forward regardless of gear. Disable for simulation games where direct throttle/brake control is preferred regardless of gear selection.

    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 vise 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. -999 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

    Convenience function for setting throttle/brakes as a single value. Use Throttle/Brake axes to apply throttle and braking separately. If the set value is larger than 0 throttle will be set, else if value is less than 0 brake axis will be set.

    Declaration
    public float Vertical { get; set; }
    Property Value
    Type Description
    float

    Methods

    CombinedInputGear<T>(Func<T, int>)

    Combines gear input from all active input providers of the specified type. Returns the highest gear number selected across all providers.

    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 -999 if no gear is selected.

    Type Parameters
    Name Description
    T

    Type of input provider to query.

    ResetShiftFlags()

    Resets all gear shift flags to their default neutral state. Called after shift operations are processed to prevent repeated shifting on the same input.

    Declaration
    public void ResetShiftFlags()

    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
    VehicleComponent.VC_Disable(bool)
    Remarks

    Component must be initialized before it can be disabled. Tracks whether disable was called by parent to manage LOD system interaction.

    VC_Initialize()

    Initializes the component's internal systems and resources. Called once during vehicle startup after the VehicleController reference is set.

    Declaration
    protected override void VC_Initialize()
    Overrides
    VehicleComponent.VC_Initialize()
    Remarks

    Override this to set up component-specific resources, cache references, or perform one-time initialization. Sets state.initialized to true on completion.

    VC_Update(float)

    Frame-rate dependent update called every frame. Override for visual updates and input handling.

    Declaration
    public override void VC_Update(float DeltaTime)
    Parameters
    Type Name Description
    float DeltaTime

    Time elapsed since last Update in seconds

    Overrides
    VehicleComponent.VC_Update(float)
    Remarks

    Only called when the component is active (initialized and enabled). Use for visual effects, UI updates, and other frame-dependent operations. Avoid physics calculations here - use VC_FixedUpdate instead.

    See Also

    VehicleInputProviderBase
    VehicleInputStates
    VehicleController
    VehicleComponent
    In this article
    Back to top Copyright © NWH - Vehicle Physics, Aerodynamics, Dynamic Water Physics