NWH Vehicle Physics 2
Search Results for

    Show / Hide Table of Contents

    Class VehicleUtility

    Static utility class for vehicle setup: CoM calculation, wheel dimension detection, suspension configuration, and inertia tensor calculation. All SI units.

    Inheritance
    object
    VehicleUtility
    Namespace: NWH.VehiclePhysics2
    Assembly: NWH.VehiclePhysics2.dll
    Syntax
    public static class VehicleUtility

    Methods

    CalculateCenterOfMass(VehicleController, float, float)

    Calculates an approximate center of mass based on wheel positions and weight distribution. Returns local coordinates suitable for direct assignment to Rigidbody.centerOfMass.

    Declaration
    public static Vector3 CalculateCenterOfMass(VehicleController vehicle, float heightOffset = -0.2, float frontBias = 0.52)
    Parameters
    Type Name Description
    VehicleController vehicle

    The vehicle controller to calculate COM for

    float heightOffset

    Vertical offset from lowest wheel point in meters. Negative values lower the COM. Typical: -0.2 to -0.4 for cars

    float frontBias

    Front weight distribution (0.5 = 50/50, 0.6 = 60% front, 0.4 = 40% front). Sports cars: 0.45-0.5, Sedans: 0.52-0.55, FWD: 0.6+

    Returns
    Type Description
    Vector3

    Center of mass position in vehicle local space

    Remarks

    Front/rear axles are auto-detected from wheel positions. Height is set relative to the lowest wheel minus the offset. Multi-axle vehicles group axles by Z position.

    CalculateInertiaTensor(float, Vector3)

    Calculates realistic inertia tensor values for vehicle dynamics. Accounts for typical vehicle mass distribution patterns.

    Declaration
    public static Vector3 CalculateInertiaTensor(float mass, Vector3 dimensions)
    Parameters
    Type Name Description
    float mass

    Vehicle mass in kilograms

    Vector3 dimensions

    Vehicle dimensions (Width x Height x Length) in meters

    Returns
    Type Description
    Vector3

    Inertia tensor suitable for Rigidbody.inertiaTensor

    Remarks

    Applies non-uniform multipliers: roll 0.8x (responsive cornering), pitch 1.2x (brake/accel stability), yaw 1.0x (balanced rotation). Adds 15% front-bias for typical engine placement.

    ConfigureSuspension(VehicleController, float, float)

    Automatically configures suspension springs and dampers for optimal ride characteristics. Sets spring rates to achieve target compression at rest and applies appropriate damping.

    Declaration
    public static void ConfigureSuspension(VehicleController vehicleController, float targetCompressionRatio = 0.33, float damperRatio = 0.26)
    Parameters
    Type Name Description
    VehicleController vehicleController

    The vehicle to configure suspension for

    float targetCompressionRatio

    Target spring compression when stationary (0.33 = 33% compressed at rest). Range: 0.2-0.4

    float damperRatio

    Damping as ratio of critical damping (0.26 = slightly underdamped). Range: 0.2-0.4 for comfort, 0.5-0.8 for sport

    Remarks

    Spring rates are calculated from mass and CoM position. Spring force is set to 3x static load for dynamic headroom. Call after mass, CoM, and wheel positions are set.

    DetectWheelDimensions(GameObject)

    Automatically detects wheel dimensions (radius and width) from a wheel GameObject's mesh bounds.

    Declaration
    public static (float radius, float width) DetectWheelDimensions(GameObject wheelObject)
    Parameters
    Type Name Description
    GameObject wheelObject

    GameObject containing the wheel mesh (visual representation)

    Returns
    Type Description
    (float radius, float width)

    Tuple containing (radius, width) in meters

    Remarks

    Combines bounds of all MeshRenderers in the wheel object. Radius = Y extent, width = smaller of X/Z extents. Assumes Y-up orientation. Returns 0.3m defaults if no renderers found. For non-standard orientations, set dimensions manually.

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