NWH Vehicle Physics 2
Search Results for

    Show / Hide Table of Contents

    Class GroundDetection

    Detects surface type under each wheel using tags (priority), terrain splatmaps, or fallback. Applies per-surface friction presets, rolling resistance, and visual/audio effects. Runs via coroutine at groundDetectionInterval. Tracks dominantSurfacePreset across all wheels. While disabled every wheel sits on the fallback surface, so nothing latches the last detected one.

    Inheritance
    object
    VehicleComponent
    GroundDetection
    Inherited Members
    VehicleComponent.state
    VehicleComponent.vehicleController
    VehicleComponent.IsActive
    VehicleComponent.VC_Initialize(VehicleController)
    VehicleComponent.VC_FixedUpdate(float)
    VehicleComponent.VC_LoadStateFromStateSettings()
    VehicleComponent.VC_Update(float)
    VehicleComponent.UpdateLOD()
    VehicleComponent.ToggleState()
    Namespace: NWH.VehiclePhysics2.GroundDetection
    Assembly: NWH.VehiclePhysics2.dll
    Syntax
    [Serializable]
    public class GroundDetection : VehicleComponent

    Fields

    dominantSurfacePreset

    Surface preset with the most wheels in contact - for vehicle-wide effects. Null if no wheels grounded or no matches found.

    Declaration
    [NonSerialized]
    public SurfacePreset dominantSurfacePreset
    Field Value
    Type Description
    SurfacePreset

    groundDetectionInterval

    Seconds between detection updates. 0.05s: responsive (player), 0.1s: balanced (default), 0.2s: low CPU (AI). Randomized ±20% at init to prevent sync between vehicles.

    Declaration
    [Tooltip("Interval in seconds between ground detection updates. Lower values = more responsive, higher CPU usage.")]
    public float groundDetectionInterval
    Field Value
    Type Description
    float

    groundDetectionPreset

    Preset containing SurfaceMaps (tags/textures to surfaces), fallback preset, and particle prefabs. Multiple vehicles can share one preset. Required for ground detection.

    Declaration
    [Tooltip("Ground detection preset containing surface maps and fallback settings.")]
    public GroundDetectionPreset groundDetectionPreset
    Field Value
    Type Description
    GroundDetectionPreset

    Properties

    DominantSurfacePreset

    Pre-14.0 name of dominantSurfacePreset.

    Declaration
    [Obsolete("Renamed to dominantSurfacePreset.")]
    public SurfacePreset DominantSurfacePreset { get; }
    Property Value
    Type Description
    SurfacePreset

    Methods

    GetCurrentSurfaceMap(WheelController, ref int, ref SurfacePreset)

    Gets surface for a wheel: checks tags first, then terrain splatmap, then fallback. Called by the detection coroutine for each wheel.

    Declaration
    public void GetCurrentSurfaceMap(WheelController wheelController, ref int surfaceIndex, ref SurfacePreset outSurfacePreset)
    Parameters
    Type Name Description
    WheelController wheelController

    Wheel to check

    int surfaceIndex

    Matched surface map index, or -1 for fallback

    SurfacePreset outSurfacePreset

    Matched or fallback surface preset

    GetDominantTerrainTexture(Vector3, Terrain)

    Returns the terrain layer index with highest weight at the given world position. Samples splatmap to find which painted texture is dominant at the wheel contact point.

    Declaration
    public int GetDominantTerrainTexture(Vector3 worldPos, Terrain terrain)
    Parameters
    Type Name Description
    Vector3 worldPos

    World position to sample

    Terrain terrain

    Terrain to sample from

    Returns
    Type Description
    int

    Dominant texture index, or -1 if sampling fails

    GetTerrainTextureComposition(Vector3, Terrain, ref float[])

    Samples the terrain splatmap at a world position and writes the per-layer weights into cellMix. Indices follow terrain texture order and the values sum to 1.

    Declaration
    public void GetTerrainTextureComposition(Vector3 worldPos, Terrain terrain, ref float[] cellMix)
    Parameters
    Type Name Description
    Vector3 worldPos

    World position to sample

    Terrain terrain

    Terrain to sample from

    float[] cellMix

    Output array receiving texture alpha values for each terrain texture

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

    Draws component gizmos in the Scene view while the vehicle is selected. Editor only, and only while the component is enabled.

    Declaration
    public override void VC_DrawGizmos()
    Overrides
    VehicleComponent.VC_DrawGizmos()

    VC_Enable(bool)

    Enables the component and starts its updates.

    Declaration
    public override bool VC_Enable(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 enabled, false otherwise

    Overrides
    VehicleComponent.VC_Enable(bool)
    Remarks

    Initializes the component first if it is not initialized yet. A parent bulk enable is refused unless the last disable also came from a parent, so it cannot resurrect a component turned off by LOD, by a script, or disabled in StateSettings.

    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
    VehicleComponent.VC_Initialize()

    VC_SetDefaults()

    Writes default values into every serialized field, and may pull default assets from Resources. Runs on vehicle reset and when the component is first added.

    Declaration
    public override void VC_SetDefaults()
    Overrides
    VehicleComponent.VC_SetDefaults()

    VC_Validate(VehicleController)

    Editor-side configuration check: null references, out-of-range values, missing dependencies. Reports through Debug.LogWarning/LogError.

    Declaration
    public override void VC_Validate(VehicleController vc)
    Parameters
    Type Name Description
    VehicleController vc

    Parent VehicleController to validate against

    Overrides
    VehicleComponent.VC_Validate(VehicleController)
    In this article
    Back to top Copyright © NWH - Vehicle Physics, Aerodynamics, Dynamic Water Physics