NWH Vehicle Physics 2
Search Results for

    Show / Hide Table of Contents

    Class Steering

    Converts steering input into per-wheel steer angles, with Ackermann geometry on two-wheel axles, speed-sensitive angle and rate reduction, and visual steering wheel animation. Front and rear steering both come from the wheel group steer coefficients.

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

    Fields

    angle

    Current steering angle in degrees applied to the wheels.

    Declaration
    [ShowInTelemetry(NaN, NaN, null, null, 1)]
    [Tooltip("Current steer angle.")]
    public float angle
    Field Value
    Type Description
    float
    Remarks

    Post-processing angle: speed-sensitive curve, rate limit and smoothing already applied. Positive is right, negative is left, normally within +/- maximumSteerAngle.

    assistCounterSteerReward

    Reduces assist when player is already counter-steering correctly (0-1). Higher values reduce intervention more when the player is already correcting.

    Declaration
    [Range(0, 1)]
    [Tooltip("Reduces assist when player counter-steers correctly. 0 = no reduction, 1 = full reduction.")]
    public float assistCounterSteerReward
    Field Value
    Type Description
    float

    assistCounterSteerThreshold

    Counter-steering angle in degrees at which the full counter-steer reward applies.

    Declaration
    [Range(1, 10)]
    [Tooltip("Counter-steering angle (deg) for the full reward. Smaller corrections receive a partial reward.")]
    public float assistCounterSteerThreshold
    Field Value
    Type Description
    float

    assistDerivativeGain

    Derivative gain for the steering assist PD controller. Higher values dampen oscillations but may reduce responsiveness.

    Declaration
    [Range(0, 1)]
    [Tooltip("Derivative gain (kD). Dampens oscillations.")]
    public float assistDerivativeGain
    Field Value
    Type Description
    float

    assistDerivativeSmoothing

    Smoothing time for the derivative term to reduce noise/jitter.

    Declaration
    [Range(0, 0.1)]
    [Tooltip("Derivative smoothing time (seconds). Reduces noise/jitter.")]
    public float assistDerivativeSmoothing
    Field Value
    Type Description
    float

    assistMaxAngle

    Maximum steering correction in degrees before strength, activation and reward scaling.

    Declaration
    [Tooltip("Maximum correction angle (degrees) before assist strength, activation and counter-steer reward scale it down.")]
    public float assistMaxAngle
    Field Value
    Type Description
    float

    assistMinSpeed

    Minimum planar speed in m/s for assist. Blends to full strength at twice this speed.

    Declaration
    [Tooltip("Minimum ground-plane speed (m/s). Assist blends in up to twice this speed, while grounded and moving forward.")]
    public float assistMinSpeed
    Field Value
    Type Description
    float

    assistOutputSmoothing

    Smoothing time for the assist output angle.

    Declaration
    [Range(0, 0.2)]
    [Tooltip("Output smoothing time (seconds). Prevents sudden corrections.")]
    public float assistOutputSmoothing
    Field Value
    Type Description
    float

    assistProportionalGain

    Proportional gain for the steering assist PD controller. Higher values increase response to current slip angle.

    Declaration
    [Range(0.1, 2)]
    [Tooltip("Proportional gain (kP). Controls response to current slip angle.")]
    public float assistProportionalGain
    Field Value
    Type Description
    float

    assistSlipThreshold

    Slip angle in degrees where assist starts blending in, reaching full strength at twice this angle.

    Declaration
    [Tooltip("Assist starts at this slip angle and blends to full strength at twice the angle (degrees).")]
    public float assistSlipThreshold
    Field Value
    Type Description
    float

    assistSpeedCurve

    Assist strength by planar speed. X = 0-50 m/s normalized to 0-1, Y = multiplier (0-1).

    Declaration
    [Tooltip("Assist strength by ground-plane speed. X: 0-50 m/s normalized, Y: strength multiplier.")]
    public AnimationCurve assistSpeedCurve
    Field Value
    Type Description
    AnimationCurve

    counterSteerRateMultiplier

    Multiplier for steering rate when counter-steering (steering opposite to vehicle slip). Higher values allow faster corrections during oversteer recovery.

    Declaration
    [Range(1, 5)]
    [Tooltip("Steering speed multiplier when counter-steering. 2-4x recommended for keyboard.")]
    public float counterSteerRateMultiplier
    Field Value
    Type Description
    float

    counterSteerSlipThreshold

    Vehicle slip angle threshold in degrees before counter-steer rate boost activates.

    Declaration
    [Tooltip("Slip angle threshold before counter-steer rate boost activates.")]
    public float counterSteerSlipThreshold
    Field Value
    Type Description
    float

    damage

    Current damage level of the steering system (0-1). Affects max angle and causes offset.

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

    damageAngleReduction

    Maximum steering angle reduction at full damage (0-1). 0.3 = 30% angle reduction at damage=1.

    Declaration
    [Range(0, 0.5)]
    [Tooltip("Inert as shipped - steering damage is never raised. Maximum steering angle reduction at full damage (0-1).")]
    public float damageAngleReduction
    Field Value
    Type Description
    float
    Remarks

    Inert as shipped. Steering.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.

    damageSteeringOffset

    Maximum steering offset (pull) in degrees at full damage. Vehicle will pull to one side.

    Declaration
    [Range(0, 15)]
    [Tooltip("Inert as shipped - steering damage is never raised. Maximum steering offset (pull) in degrees at full damage.")]
    public float damageSteeringOffset
    Field Value
    Type Description
    float
    Remarks

    Inert as shipped. Steering.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.

    degreesPerSecondLimit

    Maximum steering rate in degrees per second. Applies whenever useRawInput is false. 0 or less removes the limit.

    Declaration
    [Tooltip("Limits how fast the wheels can steer, in degrees per second. Applies whenever Raw Input is off. E.g. 60 deg/s means wheels with a 30 degree steer angle take 1 second to go from full left to full right. Set to 0 to remove the limit.")]
    [ShowInSettings("deg/s Limit", 50, 500, 10)]
    public float degreesPerSecondLimit
    Field Value
    Type Description
    float
    Remarks

    Stands in for power steering response time. 60-120 deg/s simulates a heavy vehicle; 300-500 deg/s simulates a sports car. At 30° max steer angle and 180 deg/s, full lock to lock takes 0.33 s.

    externallyAddedAngle

    Additional steering angle added to the final steering calculation. Bypasses all input processing, smoothing, and rate limiting.

    Declaration
    [Tooltip("    angle added to the user set angle, used mostly for motorcycle balancing.\r\n    To add angle to the current steer angle use this instead of angle, since this goes around smoothing and clamping.")]
    public float externallyAddedAngle
    Field Value
    Type Description
    float
    Remarks

    Added straight onto the processed angle with no smoothing or clamping, so use this rather than writing to angle for external steering sources: motorcycle balance, lane keep, stability systems.

    linearity

    Curve defining the relationship between steering input (0-1) and steering angle response (0-1). Controls the non-linearity of steering input to provide more precise control around center.

    Declaration
    public AnimationCurve linearity
    Field Value
    Type Description
    AnimationCurve
    Remarks

    X is normalized input (0 center, 1 full), Y normalized angle (0 straight, 1 max). Default is linear. An S-curve gives finer control around centre, a progressive curve dulls the centre and sharpens the extremes.

    maximumSteerAngle

    Maximum steering angle in degrees that the wheels can achieve. Defines the vehicle's turning radius and maneuverability.

    Declaration
    [Range(0, 90)]
    [ShowInSettings("Max. Steer Angle", 5, 50, 5)]
    [Tooltip("Maximum steering angle at the wheels.")]
    public float maximumSteerAngle
    Field Value
    Type Description
    float
    Remarks

    Angle at full input, before the speed-sensitive curve cuts it back at speed. Compact car 30-35°, sedan 25-30°, SUV or truck 35-45°, racing car 15-25°.

    returnToCenter

    Controls whether wheels automatically return to center position when no steering input is applied.

    Declaration
    [ShowInSettings("Return to Center")]
    [Tooltip("Should wheels return to neutral position when there is no input?")]
    public bool returnToCenter
    Field Value
    Type Description
    bool
    Remarks

    Off holds the last angle until new input arrives, for manual or externally driven centering.

    smoothTime

    Time in seconds for steering to reach its target angle. Uses SmoothDamp to give steering a sense of momentum.

    Declaration
    [Range(0.01, 0.3)]
    [ShowInSettings("Smooth Time", 0.01, 0.3, 0.01)]
    [Tooltip("Time in seconds for steering to reach target. Lower = faster response, higher = smoother/heavier feel.")]
    public float smoothTime
    Field Value
    Type Description
    float
    Remarks

    Sports car 0.04-0.06 s, sedan 0.06-0.10 s, truck or SUV 0.10-0.15 s.

    smoothing

    Not read. Serialized only so prefabs that already carry the key deserialize cleanly.

    Declaration
    [HideInInspector]
    [Obsolete("Not read. Use smoothTime.")]
    public float smoothing
    Field Value
    Type Description
    float

    speedSensitiveSteeringCurve

    Curve defining how maximum steering angle is reduced with vehicle speed for improved stability. X-axis represents normalized speed (0-1 = 0-50 m/s), Y-axis represents steering multiplier (0-1).

    Declaration
    [Tooltip("Curve that shows how the steering angle behaves at certain speed.\r\nX axis represents velocity in range 0 to 50m/s (normalized to 0,1).\r\nY axis represents 0 to maximumSteerAngle (normalized to 0,1).")]
    public AnimationCurve speedSensitiveSteeringCurve
    Field Value
    Type Description
    AnimationCurve
    Remarks

    Multiplies maximumSteerAngle by speed. Default is 1.0x at 0 km/h, 0.4x at ~54 km/h (0.3 normalized) and 0.2x at 180 km/h (1.0 normalized). Acts as a variable steering ratio: the visual steering wheel is rendered from the pre-curve angle, so it does not move on its own as speed changes.

    speedSensitiveSteeringRateCurve

    Curve defining how steering rate is reduced with vehicle speed. X-axis: normalized speed (0-1 = 0-50 m/s), Y-axis: rate multiplier (0-1).

    Declaration
    [Tooltip("Curve that reduces steering rate at higher speeds. X: speed (0-50m/s normalized), Y: rate multiplier (0-1).")]
    public AnimationCurve speedSensitiveSteeringRateCurve
    Field Value
    Type Description
    AnimationCurve
    Remarks

    This curve multiplies the smoothing value based on vehicle speed. Lower values at high speed mean slower steering response, which helps keyboard players maintain control at highway speeds. Only affects steering input rate, not return-to-center behavior.

    steeringAssistStrength

    Strength of steering assist (0 = disabled, 1 = full assist). Automatically adds counter-steer when vehicle is sliding to help maintain control.

    Declaration
    [Range(0, 1)]
    [ShowInSettings("Assist Strength", 0, 1, 0.1)]
    [Tooltip("Steering assist strength. 0 = disabled, 1 = full assist. Helps counter-steer during slides.")]
    public float steeringAssistStrength
    Field Value
    Type Description
    float

    steeringWheel

    Transform of the visual steering wheel object that will be rotated to match steering input. Leave null if no visual steering wheel rotation is needed.

    Declaration
    [Tooltip("Steering wheel transform that will be rotated when steering. Optional.")]
    public Transform steeringWheel
    Field Value
    Type Description
    Transform
    Remarks

    Rotated about its local Z by angle times steeringWheelTurnRatio. Model the wheel in the straight-ahead position; the initial local rotation is cached and used as the base.

    steeringWheelTurnRatio

    Multiplier that converts steering wheel angle to visual steering wheel rotation. Controls how many degrees the visual steering wheel rotates relative to the actual wheel steering angle.

    Declaration
    [Tooltip("Steer angle will be multiplied by this value to get steering wheel angle. Ignored if steering wheel is null.\r\nIf you want the steering wheel to rotate in opposite direction use negative value.")]
    public float steeringWheelTurnRatio
    Field Value
    Type Description
    float
    Remarks

    Stands in for the steering box reduction; real cars run 10:1 to 20:1. Sports car 12-15, sedan 16-18, truck 20-24, racing car 8-12. Negative flips the rotation direction for models authored the other way round.

    useRawInput

    Controls whether steering input is processed or applied directly to the wheels. When enabled, bypasses all smoothing, rate limiting, and speed-sensitive adjustments.

    Declaration
    [ShowInSettings("Raw Input")]
    [Tooltip("If true direct steering input will be used, without any modification.")]
    public bool useRawInput
    Field Value
    Type Description
    bool
    Remarks

    True maps input straight to wheel angle, for arcade handling, debugging or custom processing. False routes it through smoothing, speed sensitivity, the linearity curve and the rate limit, which is what gamepad and keyboard input needs.

    Methods

    CalculateSteerAngles(float)

    Calculates and applies steering angles to all wheel groups based on current input and vehicle state. Handles input processing, speed sensitivity, Ackermann geometry, and rate limiting.

    Declaration
    public virtual void CalculateSteerAngles(float DeltaTime)
    Parameters
    Type Name Description
    float DeltaTime

    Time elapsed since the last update, used for rate limiting calculations

    CalculateWheelbase()

    Calculates the wheelbase (distance between front and rear axles) for the current vehicle configuration.

    Declaration
    public float CalculateWheelbase()
    Returns
    Type Description
    float

    Wheelbase distance in meters, or -1 if fewer than two wheels carry a WheelController

    Remarks

    Longitudinal separation of the front-most and rear-most axle centres, taken from wheelController.transform.localPosition.z - the same source WheelGroup uses for trackWidth. Covers any axle count, and being the local z rather than a 3D distance it carries no track or ride-height component. Used for Ackermann calculations.

    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_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_Update(float)

    Per-frame update for input, visuals and UI. Only called while the component is active. Physics belongs in VC_FixedUpdate, not here.

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

    Time elapsed since last Update in seconds

    Overrides
    VehicleComponent.VC_Update(float)

    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)

    VisualUpdate()

    Updates the visual steering wheel rotation to match the current steering angle. Called each frame to keep visual elements synchronized with the steering state.

    Declaration
    public virtual void VisualUpdate()
    Remarks

    Rotates the steering wheel Transform around Z-axis by angle * steeringWheelTurnRatio. No-op if no steering wheel is assigned.

    See Also

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