NWH Vehicle Physics 2
Search Results for

    Show / Hide Table of Contents

    Class Brakes

    Distributes brake torque to the wheels and controls the handbrake and automatic braking, including off-throttle braking and idle braking.

    Inheritance
    object
    VehicleComponent
    Brakes
    Inherited Members
    VehicleComponent.state
    VehicleComponent.vehicleController
    VehicleComponent.IsActive
    VehicleComponent.VC_Initialize(VehicleController)
    VehicleComponent.VC_SetDefaults()
    VehicleComponent.VC_LoadStateFromStateSettings()
    VehicleComponent.VC_Update(float)
    VehicleComponent.VC_Enable(bool)
    VehicleComponent.VC_DrawGizmos()
    VehicleComponent.UpdateLOD()
    VehicleComponent.ToggleState()
    Namespace: NWH.VehiclePhysics2
    Assembly: NWH.VehiclePhysics2.dll
    Syntax
    [Serializable]
    public class Brakes : VehicleComponent
    Remarks

    This component only computes and distributes torque; the force itself is applied inside each WheelController. Distribution runs through the WheelGroups, so front/rear bias comes from their brake coefficients rather than from anything here.

    Fields

    actuationTime

    Time in seconds for brakes and handbrake to reach full actuation from zero input. Controls brake response smoothing to simulate hydraulic brake system lag.

    Declaration
    [Range(0.05, 1)]
    [Tooltip("Higher smoothing will result in brakes being applied more gradually. Floored so the clutch and powertrain get several FixedUpdates to react instead of being locked in one frame.")]
    public float actuationTime
    Field Value
    Type Description
    float
    Remarks

    Stands in for hydraulic lag and pad engagement. 0.05-0.1 s is arcade-quick, 0.1-0.2 s car-like, 0.3-0.5 s simulates a heavy vehicle or worn brakes.

    Floored at NWH.VehiclePhysics2.Brakes.MIN_ACTUATION_TIME so the ramp always spans several FixedUpdates. The auto-clutch decision and the transmission run once per FixedUpdate, so brake torque arriving in a single frame locks the wheels and drags the engine below the clutch stall floor before either can open the clutch, and the engine dies on a hard stop.

    brakeOffThrottleIntensity

    Braking force applied when throttle is released, as a percentage of maximum brake torque. Simulates engine compression braking or electric vehicle regenerative braking.

    Declaration
    [Range(0, 1)]
    [Tooltip("    Strength of off-throttle braking in percentage [0 to 1] of max braking torque.\r\n    Set to 0 to disable braking off-throttle.")]
    public float brakeOffThrottleIntensity
    Field Value
    Type Description
    float
    Remarks

    0 coasts freely. 0.1-0.3 is petrol compression braking or mild regen, 0.4-0.7 diesel compression or strong regen, 0.8-1.0 a low gear or maximum regen setting.

    brakeOnReverseDirection

    Enables automatic braking when the vehicle is moving in the opposite direction to the throttle input. Prevents unintended acceleration when trying to stop or change direction.

    Declaration
    [Tooltip("Should the vehicle apply brakes when the movement direction is opposite of the input direction?")]
    public bool brakeOnReverseDirection
    Field Value
    Type Description
    bool
    Remarks

    Rolling backwards under forward throttle brakes the rollback out before drive is applied. Turn off for pure arcade handling or custom direction-change logic.

    brakeTorqueModifiers

    List of delegate functions that modify brake torque before application to wheels. Used by modules like ABS, stability control, and traction management systems.

    Declaration
    [Tooltip("Collection of functions that modify the braking performance of the vehicle. Used by custom modules, such as a user-written ABS, where brakes need to be overridden or their effect reduced/increased. Return 1 for neutral modifier while returning 0 will disable the brakes completely. All brake torque modifiers will be multiplied in order to get the final brake torque coefficient.")]
    public List<Brakes.BrakeTorqueModifier> brakeTorqueModifiers
    Field Value
    Type Description
    List<Brakes.BrakeTorqueModifier>
    Remarks

    Each modifier returns a multiplier: 1 neutral, 0 no braking at all, above 1 for brake assist. All of them are multiplied together into one coefficient. The list starts empty. The shipped ABS and ESC modules do not use it: ABS acts through WheelController stability control, ESC through AddExternalBrakeTorque(int, float).

    brakeWhileDisabled

    Should brakes be applied when the vehicle is disabled?

    Declaration
    [FormerlySerializedAs("brakeWhileAsleep")]
    [ShowInSettings("Brake While Disabled")]
    [Tooltip("Should brakes be applied when the vehicle is disabled?")]
    public bool brakeWhileDisabled
    Field Value
    Type Description
    bool

    brakeWhileIdle

    If true, the vehicle will brake when in neutral and no throttle is applied.

    Declaration
    [ShowInSettings("Brake While Idle")]
    [Tooltip("If true, the vehicle will brake when in neutral and no throttle is applied.")]
    public bool brakeWhileIdle
    Field Value
    Type Description
    bool

    damage

    Current damage level of the braking system (0-1). At full damage, brakes lose effectiveness.

    Declaration
    [NonSerialized]
    [Tooltip("Current brake system damage (0-1).")]
    public float damage
    Field Value
    Type Description
    float

    damageBrakeTorqueReduction

    Maximum brake torque reduction at full damage (0-1). 0.6 = 60% brake torque loss when damage=1.

    Declaration
    [Range(0, 0.8)]
    [Tooltip("Inert as shipped - brake damage is never raised. Maximum brake torque reduction at full damage (0-1).")]
    public float damageBrakeTorqueReduction
    Field Value
    Type Description
    float
    Remarks

    Inert as shipped. Brakes.damage is only ever reset to 0 - DamageHandler raises damage on the engine, the transmission and the wheels only - so this multiplies a permanent zero.

    handbrakeType

    How the handbrake responds to input. Standard holds while pressed, Latching toggles on/off.

    Declaration
    [ShowInSettings("Handbrake Type")]
    [Tooltip("How the handbrake responds to input. Standard holds while pressed, Latching toggles on/off.")]
    public Brakes.HandbrakeType handbrakeType
    Field Value
    Type Description
    Brakes.HandbrakeType

    handbrakeValue

    Current value of the handbrake. 0 = inactive, 1 = maximum strength. Handbrake strength will also be affected by per wheel group handbrake settings.

    Declaration
    [Tooltip("    Current value of the handbrake. 0 = inactive, 1 = maximum strength.\r\n    Handbrake strength will also be affected by per wheel group handbrake settings.")]
    public float handbrakeValue
    Field Value
    Type Description
    float

    maxTorque

    Max brake torque that can be applied to each wheel. To adjust braking on a per-axle basis, change brake coefficients under Wheel Group settings.

    Declaration
    [Tooltip("Max brake torque that can be applied to each wheel. To adjust braking on per-axle basis change brake coefficients under Wheel Group settings.")]
    [ShowInSettings("Max. Torque", 0, 100000, 500)]
    public float maxTorque
    Field Value
    Type Description
    float

    onBrakesActivate

    Called each time brakes are activated.

    Declaration
    [Tooltip("Called each time brakes are activated.")]
    public UnityEvent onBrakesActivate
    Field Value
    Type Description
    UnityEvent

    onBrakesDeactivate

    Called each time brakes are released.

    Declaration
    [Tooltip("Called each time brakes are released.")]
    public UnityEvent onBrakesDeactivate
    Field Value
    Type Description
    UnityEvent

    Properties

    IsBraking

    True while service brake torque is applied - pedal, auto-brake (off-throttle, wrong direction, idle), brake-while-disabled, or external module torque such as ESC. Handbrake alone does not set it, so this tracks a brake light switch rather than total wheel brake torque.

    Declaration
    public bool IsBraking { get; set; }
    Property Value
    Type Description
    bool

    Methods

    AddBrakeTorqueAllWheels(float, bool)

    Applies brake torque to every wheel, clamped to maxTorque and scaled by current damage.

    Declaration
    public void AddBrakeTorqueAllWheels(float brakeTorque, bool isHandbrake = false)
    Parameters
    Type Name Description
    float brakeTorque

    Brake torque in Nm. Clamped to [0, maxTorque].

    bool isHandbrake

    True if the torque comes from the handbrake.

    AddExternalBrakeTorque(int, float)

    Accumulates signed per-wheel brake torque (Nm) from an external system such as ESC. Applied after the service brake in VC_FixedUpdate, so it survives regardless of caller order and a negative value can still trim a wheel that is already at maxTorque.

    Declaration
    public void AddExternalBrakeTorque(int wheelIndex, float brakeTorque)
    Parameters
    Type Name Description
    int wheelIndex

    Index into powertrain.wheels.

    float brakeTorque

    Brake torque in Nm. Positive adds, negative releases down to zero. The accumulated magnitude is capped at maxTorque.

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

    Fixed-timestep update for forces, torques and other physics work. Called from VehicleController.FixedUpdate(), and only while the component is active.

    Declaration
    public override void VC_FixedUpdate(float DeltaTime)
    Parameters
    Type Name Description
    float DeltaTime

    Time elapsed since last FixedUpdate in seconds

    Overrides
    VehicleComponent.VC_FixedUpdate(float)

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

    See Also

    VehicleController
    VehicleComponent
    WheelComponent
    WheelGroup
    ABSModule
    ESCModule
    In this article
    Back to top Copyright © NWH - Vehicle Physics, Aerodynamics, Dynamic Water Physics