NWH Vehicle Physics 2
Search Results for

    Show / Hide Table of Contents

    Class InputSystemVehicleInputProvider

    Vehicle input provider implementation for Unity's new Input System, supporting modern input devices with improved action-based input handling and automatic device switching.

    Inheritance
    object
    Object
    Component
    Behaviour
    MonoBehaviour
    InputProvider
    VehicleInputProviderBase
    InputSystemVehicleInputProvider
    Inherited Members
    InputProvider.Instances
    InputProvider.CombinedInput<T>(Func<T, int>)
    InputProvider.CombinedInput<T>(Func<T, float>)
    InputProvider.CombinedInput<T>(Func<T, bool>)
    InputProvider.CombinedInput<T>(Func<T, Vector2>)
    Namespace: NWH.VehiclePhysics2.Input
    Assembly: NWH.VehiclePhysics2.dll
    Syntax
    public class InputSystemVehicleInputProvider : VehicleInputProviderBase
    Remarks

    InputSystemVehicleInputProvider integrates with Unity's Input System package (com.unity.inputsystem) to provide vehicle control through keyboard, gamepad, and mouse inputs. This is Unity's modern input solution that offers improved support for multiple input devices, rebindable controls, and better support for different control schemes.

    Key features include: - Action-based input system for cleaner input handling and rebinding support - Automatic device switching (keyboard to gamepad and vice versa) - Support for multiple gamepads with proper deadzone handling - H-pattern shifter support for direct gear selection (numeric keys 0-8, minus for reverse) - Optional mouse steering similar to InputManager provider

    Input actions are defined in the VehicleInputActions.inputactions asset file. To customize key bindings, double-click the VehicleInputActions asset in the project window and modify the bindings in the Input Actions editor window. The VehicleInputActions.cs file is auto-generated from this asset.

    Requires the Unity Input System package to be installed.

    Fields

    mouseInput

    When enabled, uses mouse position for steering and throttle/brake inputs instead of keyboard/gamepad. Mouse horizontal position controls steering, vertical position controls throttle (upper half) and brakes (lower half).

    Declaration
    [Tooltip("Should mouse be used for input?")]
    public bool mouseInput
    Field Value
    Type Description
    bool

    vehicleInputActions

    Shared instance of VehicleInputActions containing all input action definitions. Auto-generated from the VehicleInputActions.inputactions asset file.

    Declaration
    public static VehicleInputActions vehicleInputActions
    Field Value
    Type Description
    VehicleInputActions

    Methods

    Awake()

    Initializes the Input System actions and sets up gear shift input callbacks. Creates the VehicleInputActions instance, enables it, and registers callbacks for all H-shifter gears.

    Declaration
    public override void Awake()
    Overrides
    NWH.Common.Input.InputProvider.Awake()

    Boost()

    Returns true while the boost button is held down. Only functional when NOSModule or similar boost module is present and enabled. Provides temporary power increase when active.

    Declaration
    public override bool Boost()
    Returns
    Type Description
    bool

    True while button is pressed.

    Overrides
    VehicleInputProviderBase.Boost()

    Brakes()

    Returns the current brake input value normalized to [0, 1] range. 0 means no braking, 1 means full braking force.

    Declaration
    public override float Brakes()
    Returns
    Type Description
    float

    Brake input value between 0 and 1.

    Overrides
    VehicleInputProviderBase.Brakes()

    Clutch()

    Returns the current clutch input value normalized to [0, 1] range. 0 means clutch fully engaged (pedal released), 1 means clutch fully disengaged (pedal pressed). Used with manual transmissions for gear changes and preventing engine stalls.

    Declaration
    public override float Clutch()
    Returns
    Type Description
    float

    Clutch input value between 0 and 1.

    Overrides
    VehicleInputProviderBase.Clutch()

    CruiseControl()

    Returns true when the cruise control toggle button is pressed this frame. Only functional when CruiseControlModule is present and enabled. Maintains constant vehicle speed without throttle input.

    Declaration
    public override bool CruiseControl()
    Returns
    Type Description
    bool

    True if button was pressed this frame.

    Overrides
    VehicleInputProviderBase.CruiseControl()

    EngineStartStop()

    Returns true when the engine start/stop button is pressed this frame. Toggles the engine on/off state.

    Declaration
    public override bool EngineStartStop()
    Returns
    Type Description
    bool

    True if button was pressed this frame.

    Overrides
    VehicleInputProviderBase.EngineStartStop()

    ExtraLights()

    Returns true when the extra lights toggle button is pressed this frame. Controls auxiliary lights such as fog lights, work lights, or off-road lights.

    Declaration
    public override bool ExtraLights()
    Returns
    Type Description
    bool

    True if button was pressed this frame.

    Overrides
    VehicleInputProviderBase.ExtraLights()

    FlipOver()

    Returns true when the flip-over button is pressed this frame. Only functional when FlipOverModule is present and enabled, used to right overturned vehicles.

    Declaration
    public override bool FlipOver()
    Returns
    Type Description
    bool

    True if button was pressed this frame.

    Overrides
    VehicleInputProviderBase.FlipOver()

    Handbrake()

    Returns the current handbrake input value normalized to [0, 1] range. 0 means released, 1 means fully engaged. Typically used for drifting or parking.

    Declaration
    public override float Handbrake()
    Returns
    Type Description
    float

    Handbrake input value between 0 and 1.

    Overrides
    VehicleInputProviderBase.Handbrake()

    HazardLights()

    Returns true when the hazard lights toggle button is pressed this frame. Activates all turn signals simultaneously for emergency warning.

    Declaration
    public override bool HazardLights()
    Returns
    Type Description
    bool

    True if button was pressed this frame.

    Overrides
    VehicleInputProviderBase.HazardLights()

    HighBeamLights()

    Returns true when the high beam headlights toggle button is pressed this frame. Switches headlights between low beam and high beam mode.

    Declaration
    public override bool HighBeamLights()
    Returns
    Type Description
    bool

    True if button was pressed this frame.

    Overrides
    VehicleInputProviderBase.HighBeamLights()

    Horn()

    Returns true while the horn button is held down. Unlike toggle buttons, this is typically held for continuous horn sound.

    Declaration
    public override bool Horn()
    Returns
    Type Description
    bool

    True while button is pressed.

    Overrides
    VehicleInputProviderBase.Horn()

    LeftBlinker()

    Returns true when the left turn signal button is pressed this frame. Toggles the left turn indicator on/off.

    Declaration
    public override bool LeftBlinker()
    Returns
    Type Description
    bool

    True if button was pressed this frame.

    Overrides
    VehicleInputProviderBase.LeftBlinker()

    LowBeamLights()

    Returns true when the low beam headlights toggle button is pressed this frame. Turns the main headlights on or off.

    Declaration
    public override bool LowBeamLights()
    Returns
    Type Description
    bool

    True if button was pressed this frame.

    Overrides
    VehicleInputProviderBase.LowBeamLights()

    OnDestroy()

    Declaration
    public override void OnDestroy()
    Overrides
    NWH.Common.Input.InputProvider.OnDestroy()

    OnDisable()

    Disables the Input System actions when the component is disabled.

    Declaration
    public void OnDisable()

    OnEnable()

    Enables the Input System actions when the component is enabled.

    Declaration
    public void OnEnable()

    RightBlinker()

    Returns true when the right turn signal button is pressed this frame. Toggles the right turn indicator on/off.

    Declaration
    public override bool RightBlinker()
    Returns
    Type Description
    bool

    True if button was pressed this frame.

    Overrides
    VehicleInputProviderBase.RightBlinker()

    ShiftDown()

    Returns true when the sequential shift down button is pressed this frame. Shifts transmission to the next lower gear in sequential mode.

    Declaration
    public override bool ShiftDown()
    Returns
    Type Description
    bool

    True if button was pressed this frame.

    Overrides
    VehicleInputProviderBase.ShiftDown()

    ShiftInto()

    Returns the directly selected gear index for H-pattern shifters. Supports numeric keys 0-8 for forward gears, minus key for reverse (-1), and 0 for neutral. Returns -999 if no gear key is currently held.

    Declaration
    public override int ShiftInto()
    Returns
    Type Description
    int

    Gear index (-1 for reverse, 0 for neutral, 1-8 for forward gears), or -999 if no gear is selected.

    Overrides
    VehicleInputProviderBase.ShiftInto()

    ShiftUp()

    Returns true when the sequential shift up button is pressed this frame. Shifts transmission to the next higher gear in sequential mode.

    Declaration
    public override bool ShiftUp()
    Returns
    Type Description
    bool

    True if button was pressed this frame.

    Overrides
    VehicleInputProviderBase.ShiftUp()

    Steering()

    Returns the current steering input value normalized to [-1, 1] range. -1 means full left, 0 means centered, 1 means full right.

    Declaration
    public override float Steering()
    Returns
    Type Description
    float

    Steering input value between -1 and 1.

    Overrides
    VehicleInputProviderBase.Steering()

    Throttle()

    Returns the current throttle input value normalized to [0, 1] range. 0 means no throttle, 1 means full throttle.

    Declaration
    public override float Throttle()
    Returns
    Type Description
    float

    Throttle input value between 0 and 1.

    Overrides
    VehicleInputProviderBase.Throttle()

    TrailerAttachDetach()

    Returns true when the trailer attach/detach button is pressed this frame. Only functional when TrailerHitchModule is present and enabled on the vehicle.

    Declaration
    public override bool TrailerAttachDetach()
    Returns
    Type Description
    bool

    True if button was pressed this frame.

    Overrides
    VehicleInputProviderBase.TrailerAttachDetach()

    Update()

    Updates cached input values from Input System every frame. Reads all analog inputs (throttle, brakes, steering, clutch, handbrake) and stores them for access. Uses mouse position instead when mouseInput is enabled.

    Declaration
    public void Update()
    In this article
    Back to top Copyright © NWH - Vehicle Physics, Aerodynamics, Dynamic Water Physics