NWH Vehicle Physics 2
Search Results for

    Show / Hide Table of Contents

    GUI

    Vehicle Physics provides dashboard UI components for creating realistic in-game vehicle displays.

    Overview

    The GUI system consists of a central controller (DashGUIController) that reads vehicle data and updates individual UI components:

    • Gauges: Display numerical values (speed, RPM)
    • Dash Lights: Show warning/indicator states (ABS, TCS, check engine, turn signals, etc.)
    • Steering Wheel: Touch-based steering input for mobile devices

    All components are Unity UI-based (Canvas, Image, Text) and designed for performance with minimal allocations.

    Data Source Modes

    DashGUIController supports two data source modes:

    • VehicleController: Reads from a specific vehicle assigned in the inspector. Use for single-vehicle setups or dedicated dashboards.
    • VehicleChanger: Automatically tracks the active vehicle from VehicleChanger. Use for multi-vehicle scenarios with vehicle switching.

    Setup

    1. Add a Canvas to your scene with DashGUIController component
    2. Create child UI elements for gauges and lights
    3. Assign references in DashGUIController and enable corresponding toggles (e.g., useAnalogSpeedGauge)
    4. Set dataSource and optionally assign vehicleController

    The dashboard canvas automatically enables/disables when the vehicle is enabled/disabled.

    Components

    DashGUIController

    Central controller that reads vehicle data and updates all dashboard elements.

    Key Properties:

    • dataSource: VehicleController or VehicleChanger mode
    • vehicleController: Target vehicle (VehicleController mode only)
    • useXXX toggles: Enable/disable individual components

    Supported Elements:

    • Analog/digital RPM and speed gauges
    • Digital gear indicator
    • ABS, TCS, check engine lights
    • Turn signal (blinker) indicators
    • Low/high beam headlight indicators

    AnalogGauge

    Rotating needle gauge for speedometers and tachometers.

    Key Properties:

    • maxValue: Maximum displayable value (e.g., 240 for 240 km/h, 8000 for 8000 RPM)
    • startAngle/endAngle: Needle rotation limits in degrees (Z-axis)
    • needleSmoothing: 0-1 value for needle inertia (0 = instant, 1 = maximum smoothing)
    • lockAtStart/lockAtEnd: Calibration helpers (play mode only)

    Requirements:

    • Child GameObject named "Needle" that rotates to display values

    Property:

    • Value: Current gauge value (clamped to 0-maxValue)

    DigitalGauge

    Text-based display for numerical or string values with optional progress bar.

    Key Properties:

    • gaugeType: Numerical (speed/RPM with formatting) or Textual (gear names)
    • format: C# format string for numerical values (e.g., "0" = no decimals, "0.0" = one decimal)
    • numericalSmoothing: 0-1 smoothing factor for numerical displays
    • showProgressBar: Enable horizontal fill bar visualization
    • maxValue: Maximum value for progress bar percentage
    • unit: Unit text appended after value (e.g., "km/h", "RPM")

    Requirements:

    • Child GameObject named "Readout" with Text component
    • Optional child GameObject named "Line" with Image component (for progress bar)

    Properties:

    • numericalValue: Float value to display (Numerical mode)
    • stringValue: String value to display (Textual mode)

    DashLight

    Warning/indicator light with smooth transitions and anti-flicker features.

    Key Properties:

    • onColor/offColor: Image colors for active/inactive states
    • holdTime: Duration to hold light on after state becomes false (prevents flickering from ABS/TCS)
    • fadeTime: Fade-out duration in seconds (simulates incandescent bulb dimming)

    Requirements:

    • Image component on the same GameObject

    Property:

    • Active: Gets/sets light state (true = on, false = begins hold/fade-out sequence)

    SteeringWheel

    Touch-based steering control for mobile input. Tracks drag input and returns normalized steering values.

    Key Properties:

    • steeringWheelGraphic: UI Graphic (Image) representing the steering wheel
    • maximumSteeringAngle: Max rotation angle per side in degrees (e.g., 200-450)
    • returnToCenterSpeed: Auto-center rotation speed in degrees/second

    Method:

    • GetClampedValue(): Returns normalized steering input [-1, 1]

    Behavior:

    • Rotates based on touch/mouse drag relative to wheel center
    • Automatically returns to center when released
    • Based on Unity Forums code by yasirkula
    In this article
    Back to top Copyright © NWH - Vehicle Physics, Aerodynamics, Dynamic Water Physics