NWH Vehicle Physics 2
Search Results for

    Show / Hide Table of Contents

    Class MobileVehicleInputProvider

    Vehicle input provider implementation for mobile platforms, supporting touch controls, on-screen buttons, steering wheels, and device accelerometer/gyroscope input.

    Inheritance
    object
    Object
    Component
    Behaviour
    MonoBehaviour
    InputProvider
    VehicleInputProviderBase
    MobileVehicleInputProvider
    Inherited Members
    InputProvider.Instances
    InputProvider.OnDestroy()
    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
    [RequireComponent(typeof(MobileSceneInputProvider))]
    public class MobileVehicleInputProvider : VehicleInputProviderBase
    Remarks

    MobileVehicleInputProvider is designed specifically for mobile games, providing multiple input methods optimized for touchscreen devices. It works in conjunction with MobileSceneInputProvider for scene-level controls (camera switching, pause menu, etc.) and MobileInputButton components for on-screen UI buttons.

    Supported input methods: - Touch buttons: On-screen buttons for throttle, brake, gear shifting, and auxiliary controls - Steering wheel: Draggable on-screen steering wheel for precise steering control - Accelerometer: Device tilt for steering and/or throttle/brake control - Screen areas: Different screen regions can trigger different inputs

    Each input method can be configured independently. For example, you can use accelerometer steering combined with button-based throttle/brake, or steering wheel with screen-based throttle control. All button assignments are optional - leave fields empty for inputs you don't need.

    For complete mobile input setup: 1. Add MobileSceneInputProvider to the scene for scene-level controls 2. Add MobileVehicleInputProvider to the vehicle 3. Create UI canvas with MobileInputButton components 4. Assign the buttons to appropriate fields in this component 5. Configure input types (steering and vertical axis) based on your game's control scheme

    Fields

    boostButton

    Reference to the on-screen boost button. Optional, leave null if not needed.

    Declaration
    public MobileInputButton boostButton
    Field Value
    Type Description
    MobileInputButton

    brakeButton

    Reference to the on-screen brake button. Required when verticalInputType is set to Button.

    Declaration
    public MobileInputButton brakeButton
    Field Value
    Type Description
    MobileInputButton

    cruiseControlButton

    Reference to the on-screen cruise control toggle button. Optional, leave null if not needed.

    Declaration
    public MobileInputButton cruiseControlButton
    Field Value
    Type Description
    MobileInputButton

    engineStartStopButton

    Reference to the on-screen engine start/stop toggle button. Optional, leave null if not needed.

    Declaration
    public MobileInputButton engineStartStopButton
    Field Value
    Type Description
    MobileInputButton

    extraLightsButton

    Reference to the on-screen extra lights toggle button. Optional, leave null if not needed.

    Declaration
    public MobileInputButton extraLightsButton
    Field Value
    Type Description
    MobileInputButton

    flipOverButton

    Reference to the on-screen flip-over button. Optional, leave null if not needed.

    Declaration
    public MobileInputButton flipOverButton
    Field Value
    Type Description
    MobileInputButton

    handbrakeButton

    Reference to the on-screen handbrake button. Optional, leave null if not needed.

    Declaration
    public MobileInputButton handbrakeButton
    Field Value
    Type Description
    MobileInputButton

    hazardLightsButton

    Reference to the on-screen hazard lights toggle button. Optional, leave null if not needed.

    Declaration
    public MobileInputButton hazardLightsButton
    Field Value
    Type Description
    MobileInputButton

    highBeamLightsButton

    Reference to the on-screen high beam lights toggle button. Optional, leave null if not needed.

    Declaration
    public MobileInputButton highBeamLightsButton
    Field Value
    Type Description
    MobileInputButton

    hornButton

    Reference to the on-screen horn button. Optional, leave null if not needed.

    Declaration
    public MobileInputButton hornButton
    Field Value
    Type Description
    MobileInputButton

    leftBlinkerButton

    Reference to the on-screen left turn signal toggle button. Optional, leave null if not needed.

    Declaration
    public MobileInputButton leftBlinkerButton
    Field Value
    Type Description
    MobileInputButton

    lowBeamLightsButton

    Reference to the on-screen low beam lights toggle button. Optional, leave null if not needed.

    Declaration
    public MobileInputButton lowBeamLightsButton
    Field Value
    Type Description
    MobileInputButton

    rightBlinkerButton

    Reference to the on-screen right turn signal toggle button. Optional, leave null if not needed.

    Declaration
    public MobileInputButton rightBlinkerButton
    Field Value
    Type Description
    MobileInputButton

    shiftDownButton

    Reference to the on-screen shift down button for sequential shifting. Optional, leave null if not needed.

    Declaration
    public MobileInputButton shiftDownButton
    Field Value
    Type Description
    MobileInputButton

    shiftUpButton

    Reference to the on-screen shift up button for sequential shifting. Optional, leave null if not needed.

    Declaration
    public MobileInputButton shiftUpButton
    Field Value
    Type Description
    MobileInputButton

    steerLeftButton

    On-screen button for steering left. Required only when steeringInputType is set to Button.

    Declaration
    public MobileInputButton steerLeftButton
    Field Value
    Type Description
    MobileInputButton

    steerRightButton

    On-screen button for steering right. Required only when steeringInputType is set to Button.

    Declaration
    public MobileInputButton steerRightButton
    Field Value
    Type Description
    MobileInputButton

    steeringInputType

    Currently active steering input method. Configure this to match your mobile UI setup (steering wheel, accelerometer, buttons, etc.).

    Declaration
    [FormerlySerializedAs("horizontalInputType")]
    [Tooltip("Active steer devices.")]
    public MobileVehicleInputProvider.HorizontalAxisType steeringInputType
    Field Value
    Type Description
    MobileVehicleInputProvider.HorizontalAxisType

    steeringWheel

    Reference to the SteeringWheel component when using HorizontalAxisType.SteeringWheel. Required only if steeringInputType is set to SteeringWheel.

    Declaration
    [Tooltip("Steering wheel script. Optional and not needed if SteeringWheel option is not used.")]
    public SteeringWheel steeringWheel
    Field Value
    Type Description
    SteeringWheel

    throttleButton

    On-screen button for throttle input. Required only when verticalInputType is set to Button.

    Declaration
    public MobileInputButton throttleButton
    Field Value
    Type Description
    MobileInputButton

    tiltSensitivity

    Multiplier for accelerometer sensitivity. Higher values increase steering/throttle response to device tilt. Only applies when using Accelerometer input type. Typical range: 1.0 to 2.5.

    Declaration
    [Tooltip("Higher value will result in higher steer angle for same tilt.")]
    public float tiltSensitivity
    Field Value
    Type Description
    float

    trailerAttachDetachButton

    On-screen button for attaching/detaching trailers. Optional.

    Declaration
    public MobileInputButton trailerAttachDetachButton
    Field Value
    Type Description
    MobileInputButton

    verticalInputType

    Currently active throttle/brake input method. Configure this to match your mobile UI setup (buttons, accelerometer, screen areas, etc.).

    Declaration
    [Tooltip("Active vertical input type.")]
    public MobileVehicleInputProvider.VerticalAxisType verticalInputType
    Field Value
    Type Description
    MobileVehicleInputProvider.VerticalAxisType

    Methods

    Awake()

    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()

    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()

    H-pattern shifter support is not implemented for mobile input. Mobile devices typically use sequential shifting (shift up/down buttons).

    Declaration
    public override int ShiftInto()
    Returns
    Type Description
    int

    Always returns -999 (no gear 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()
    In this article
    Back to top Copyright © NWH - Vehicle Physics, Aerodynamics, Dynamic Water Physics