Class TransmissionComponent
Transmission system component that handles gear ratios, shifting logic, and power transmission from the engine through clutch to differential or wheels.
Inherited Members
Namespace: NWH.VehiclePhysics2.Powertrain
Assembly: NWH.VehiclePhysics2.dll
Syntax
[Serializable]
public class TransmissionComponent : PowertrainComponent
Remarks
The TransmissionComponent simulates various transmission types including automatic, manual, sequential, and CVT transmissions. It manages gear ratios, shift points, and clutch engagement to provide realistic power delivery and driving characteristics for different vehicle types.
Key features include: - Multiple transmission types: Automatic, Manual, Sequential, CVT, and External (custom) - Configurable gear ratios with reverse and forward gears - Automatic shift point calculation based on engine characteristics - Manual shift logic with clutch control simulation - Sequential transmission for racing applications - CVT with infinite gear ratios within specified range - Drive/Neutral/Reverse (DNR) modes for automatic transmissions
The transmission works in conjunction with the clutch component to manage power transfer. Automatic transmissions handle clutch engagement automatically, while manual transmissions require player input or external clutch control. Shift quality and timing can be adjusted to simulate different transmission characteristics from smooth luxury to aggressive performance.
Fields
allowDownshiftGearSkipping
Allows automatic transmission to skip gears when downshifting (e.g., 5th to 2nd gear).
Declaration
public bool allowDownshiftGearSkipping
Field Value
| Type | Description |
|---|---|
| bool |
Remarks
When enabled in automatic non-sequential mode, the transmission can skip multiple gears during aggressive downshifts, providing faster response when heavy braking or rapid deceleration occurs. Useful for trucks and performance vehicles. Has no effect in sequential or manual modes.
allowUpshiftGearSkipping
Allows automatic transmission to skip gears when upshifting (e.g., 2nd to 4th gear).
Declaration
public bool allowUpshiftGearSkipping
Field Value
| Type | Description |
|---|---|
| bool |
Remarks
When enabled in automatic non-sequential mode, the transmission can skip gears during light throttle acceleration to improve fuel efficiency. Common in modern automatic transmissions. Has no effect in sequential or manual modes.
automaticTransmissionDNRShiftType
Behavior when switching from neutral to forward or reverse gear.
Declaration
[FormerlySerializedAs("automaticTransmissionReverseType")]
[FormerlySerializedAs("reverseType")]
[Tooltip("Behavior when switching from neutral to forward or reverse gear.")]
public TransmissionComponent.AutomaticTransmissionDNRShiftType automaticTransmissionDNRShiftType
Field Value
| Type | Description |
|---|---|
| TransmissionComponent.AutomaticTransmissionDNRShiftType |
clutchInputShiftThreshold
If set to >0, the clutch will need to be released to the value below the set number for gear shifts to occur.
Declaration
[Tooltip("If set to >0, the clutch will need to be released to the value below the set number\r\nfor gear shifts to occur.")]
public float clutchInputShiftThreshold
Field Value
| Type | Description |
|---|---|
| float |
currentGearRatio
Current gear ratio.
Declaration
[Tooltip("Current gear ratio.")]
[ShowInTelemetry(NaN, NaN, null, null, 1)]
public float currentGearRatio
Field Value
| Type | Description |
|---|---|
| float |
cvtResponseRate
How quickly the CVT ratio adjusts. Higher values provide faster response.
Declaration
[Range(1, 20)]
[Tooltip("How quickly the CVT ratio adjusts (1-20). Higher = faster response.")]
public float cvtResponseRate
Field Value
| Type | Description |
|---|---|
| float |
cvtTargetRPMPercent
Target engine RPM percent (0-1) the CVT will try to maintain. Lower values favor fuel efficiency, higher values favor performance.
Declaration
[Range(0.3, 0.9)]
[Tooltip("Target engine RPM percent (0-1) the CVT will try to maintain. Lower = efficiency, higher = performance.")]
public float cvtTargetRPMPercent
Field Value
| Type | Description |
|---|---|
| float |
damageShiftDurationMultiplier
Maximum shift duration multiplier at full damage. 3 = 3x longer shifts at damage=1.
Declaration
[Range(1, 5)]
[Tooltip("Maximum shift duration multiplier at full damage. 3 = 3x longer shifts when damage=1.")]
public float damageShiftDurationMultiplier
Field Value
| Type | Description |
|---|---|
| float |
dnrSpeedThreshold
Speed at which the vehicle can switch between D/N/R gears.
Declaration
[Tooltip("Speed at which the vehicle can switch between D/N/R gears.")]
public float dnrSpeedThreshold
Field Value
| Type | Description |
|---|---|
| float |
finalGearRatio
Final gear multiplier. Each gear gets multiplied by this value. Equivalent to an axle/differential ratio in real life.
Declaration
[Tooltip(" Final gear multiplier. Each gear gets multiplied by this value.\r\n Equivalent to axle/differential ratio in real life.")]
[ShowInSettings("Final Ratio", 1, 20, 1)]
public float finalGearRatio
Field Value
| Type | Description |
|---|---|
| float |
forwardGearCount
Number of forward gears.
Declaration
[Tooltip("Number of forward gears.")]
public int forwardGearCount
Field Value
| Type | Description |
|---|---|
| int |
gearIndex
Current gear index in the gear list. Different from gear because gear uses -1 = R, 0 = N and D = 1, while this is the absolute index in the range of 0 to gear list size minus one. Use Gear to get the actual gear.
Declaration
[NonSerialized]
[ShowInTelemetry(NaN, NaN, null, null, 1)]
[Tooltip("Current gear index in the gears list.\r\nDifferent from gear because gear uses -1 = R, 0 = N and D = 1, while this is the absolute index\r\nin the range of 0 to gear list size minus one.\r\nUse Gear to get the actual gear.")]
public int gearIndex
Field Value
| Type | Description |
|---|---|
| int |
gears
A list of gears ratios in order of negative, neutral and then positive. E.g., -4, 0, 6, 4, 3, 2.
Declaration
[SerializeField]
[Tooltip("A list of gears ratios in order of negative, neutral and then positive.\r\nE.g. -4, 0, 6, 4, 3, 2 => one reverse, 4 forward gears.")]
public List<float> gears
Field Value
| Type | Description |
|---|---|
| List<float> |
holdToKeepInGear
If true, the gear input has to be held for the transmission to stay in gear; otherwise it goes to neutral. Used for hardware H-shifters.
Declaration
[Tooltip("If true the gear input has to be held for the transmission to stay in gear, otherwise it goes to neutral.\r\nUsed for hardware H-shifters.")]
public bool holdToKeepInGear
Field Value
| Type | Description |
|---|---|
| bool |
ignorePostShiftBanInManual
If enabled, manual transmission shifts skip the post-shift ban so the user can shift again immediately.
Declaration
[Tooltip("If enabled, manual transmission shifts skip the post-shift ban so the user can shift again immediately.")]
public bool ignorePostShiftBanInManual
Field Value
| Type | Description |
|---|---|
| bool |
inclineEffectCoeff
How much incline affects shift point position? Higher value will push the shift up and shift down RPM up depending on the current incline to prevent the vehicle from upshifting at the wrong time.
Declaration
[Range(0, 4)]
[Tooltip("How much inclines affect shift point position. Higher value will push the shift up and shift down RPM up depending \r\non the current incline to prevent vehicle from upshifting at the wrong time.")]
public float inclineEffectCoeff
Field Value
| Type | Description |
|---|---|
| float |
isPostShiftBanActive
Is the transmission currently in the post-shift phase in which the shifting is disabled/banned to prevent gear hunting?
Declaration
[Tooltip("Is the transmission currently in the post-shift phase in which the shifting is disabled/banned to prevent gear hunting?")]
public bool isPostShiftBanActive
Field Value
| Type | Description |
|---|---|
| bool |
isSequential
Is the automatic gearbox sequential? Has no effect on manual transmission.
Declaration
[ShowInSettings("Sequential")]
[Tooltip("Is the automatic gearbox sequential?\r\nHas no effect on manual transmission.")]
public bool isSequential
Field Value
| Type | Description |
|---|---|
| bool |
isShifting
Is a gear shift currently in progress.
Declaration
[ShowInTelemetry(NaN, NaN, null, null, 1)]
[Tooltip("Is a gear shift currently in progress.")]
public bool isShifting
Field Value
| Type | Description |
|---|---|
| bool |
onDownshift
Event that gets triggered when transmission shifts down.
Declaration
[SerializeField]
[Tooltip("Event that gets triggered when transmission shifts down.")]
public UnityEvent onDownshift
Field Value
| Type | Description |
|---|---|
| UnityEvent |
onShift
Event that gets triggered when transmission shifts (up or down).
Declaration
[SerializeField]
[Tooltip("Event that gets triggered when transmission shifts (up or down).")]
public UnityEvent onShift
Field Value
| Type | Description |
|---|---|
| UnityEvent |
onUpshift
Event that gets triggered when transmission shifts up.
Declaration
[SerializeField]
[Tooltip("Event that gets triggered when transmission shifts up.")]
public UnityEvent onUpshift
Field Value
| Type | Description |
|---|---|
| UnityEvent |
postShiftBan
Time after shifting in which shifting cannot be done again.
Declaration
[Tooltip("Time after shifting in which shifting cannot be done again.")]
public float postShiftBan
Field Value
| Type | Description |
|---|---|
| float |
referenceShiftRPM
Declaration
[NonSerialized]
public float referenceShiftRPM
Field Value
| Type | Description |
|---|---|
| float |
reverseGearCount
Number of reverse gears.
Declaration
[Tooltip("Number of reverse gears.")]
public int reverseGearCount
Field Value
| Type | Description |
|---|---|
| int |
shiftDelegate
Function that changes the gears as required. Use transmissionType External and assign this delegate to use your own gear shift code.
Declaration
[Tooltip("Function that changes the gears as required.\r\nUse transmissionType External and assign this delegate to use your own gear shift code.")]
public TransmissionComponent.Shift shiftDelegate
Field Value
| Type | Description |
|---|---|
| TransmissionComponent.Shift |
shiftDuration
Time it takes transmission to shift between gears.
Declaration
[ShowInSettings("Shift Duration", 0.001, 0.5, 0.05)]
[Tooltip("Time it takes transmission to shift between gears.")]
public float shiftDuration
Field Value
| Type | Description |
|---|---|
| float |
shiftInAir
Should the transmission shift while the vehicle is fully in the air? All wheels must be off the ground for it to be considered as in air.
Declaration
[Tooltip("Should the transmission shift while the vehicle is fully in air. All wheels must be off the ground for it to be considered as in air.")]
public bool shiftInAir
Field Value
| Type | Description |
|---|---|
| bool |
shiftProgress
Progress of the current gear shift in range of 0 to 1.
Declaration
[Tooltip("Progress of the current gear shift in range of 0 to 1.")]
public float shiftProgress
Field Value
| Type | Description |
|---|---|
| float |
transmissionType
Determines in which way gears can be changed. Manual - gears can only be shifted by manual user input. Automatic - automatic gear changing. Allows for gear skipping (e.g., 3rd->5th) which can be useful in trucks and other high-gear count vehicles. AutomaticSequential - automatic gear changing but only one gear at a time can be shifted (e.g., 3rd->4th)
Declaration
[SerializeField]
[Tooltip("Manual - gears can only be shifted by manual user input. Automatic - automatic gear changing. Allows for gear skipping (e.g. 3rd->5th) which can be useful in trucks and other high gear count vehicles. AutomaticSequential - automatic gear changing but only one gear at the time can be shifted (e.g. 3rd->4th)")]
[ShowInSettings("Type")]
[FormerlySerializedAs("_transmissionType")]
public TransmissionComponent.TransmissionShiftType transmissionType
Field Value
| Type | Description |
|---|---|
| TransmissionComponent.TransmissionShiftType |
triedToShiftWithoutClutch
Called when the user tries to shift without the clutch input and the clutch shift threshold is below 1.
Declaration
[Tooltip("Called when user tries to shift without clutch input and the clutch shift threshold is below 1.")]
public UnityEvent triedToShiftWithoutClutch
Field Value
| Type | Description |
|---|---|
| UnityEvent |
variableShiftIntensity
How far the shift points drop below their configured RPMs at light throttle. 0 keeps them fixed; higher values shift earlier the lighter the load.
Declaration
[Range(0, 1)]
[Tooltip("How far the shift points drop below their configured RPMs at light throttle. 0 = fixed, higher = earlier shifts when coasting.")]
public float variableShiftIntensity
Field Value
| Type | Description |
|---|---|
| float |
variableShiftPoint
If enabled, transmission will adjust both the shift up and down points to match the current load.
Declaration
[ShowInSettings("Variable Shift Point")]
[Tooltip("If enabled, transmission will adjust both the shift up and down points to match the current load.")]
public bool variableShiftPoint
Field Value
| Type | Description |
|---|---|
| bool |
Properties
DownshiftRPM
Full-load RPM at which the automatic transmission shifts down. With variable shift point on, the live point drops below this at lighter throttle; use TargetDownshiftRPM for the current value.
Declaration
public float DownshiftRPM { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
Gear
0 for neutral, less than 0 for reverse gears and lager than 0 for forward gears. Use 'ShiftInto' to set gear.
Declaration
public int Gear { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
GearName
Returns the current gear name as a string, e.g. "R", "R2", "N" or "1"
Declaration
public string GearName { get; }
Property Value
| Type | Description |
|---|---|
| string |
TargetDownshiftRPM
Live downshift threshold used for shift decisions, derived from DownshiftRPM scaled by load and adjusted for incline. Equals DownshiftRPM at full throttle.
Declaration
public float TargetDownshiftRPM { get; }
Property Value
| Type | Description |
|---|---|
| float |
TargetUpshiftRPM
Live upshift threshold used for shift decisions, derived from UpshiftRPM scaled by load and adjusted for incline. Equals UpshiftRPM at full throttle.
Declaration
public float TargetUpshiftRPM { get; }
Property Value
| Type | Description |
|---|---|
| float |
UpshiftRPM
Full-load RPM at which the automatic transmission shifts up. With variable shift point on, the live point drops below this at lighter throttle; use TargetUpshiftRPM for the current value.
Declaration
public float UpshiftRPM { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
Methods
ForwardStep(float, float, float)
Performs the forward pass of torque transmission through the powertrain chain.
Declaration
public override float ForwardStep(float torque, float inertiaSum, float DeltaTime)
Parameters
| Type | Name | Description |
|---|---|---|
| float | torque | The input torque in N⋅m. |
| float | inertiaSum | The accumulated inertia of all upstream components in kg⋅m². |
| float | DeltaTime | The simulation delta time in seconds. |
Returns
| Type | Description |
|---|---|
| float | The final torque after processing through all connected components. |
Overrides
Remarks
Part of solver pass 2: propagates torque from engine toward wheels. Components apply gear ratios, losses, etc. Returns input torque if no output connected.
GetGearRatio(int)
Gets the total gear ratio for the specified gear, including final drive ratio.
Declaration
public float GetGearRatio(int g)
Parameters
| Type | Name | Description |
|---|---|---|
| int | g | Gear number (-1 for reverse, 0 for neutral, 1+ for forward gears) |
Returns
| Type | Description |
|---|---|
| float | Combined gear ratio (transmission gear × final drive ratio) |
Remarks
The returned value represents the complete ratio from transmission input to output, including both the individual gear ratio and the final drive reduction. Higher ratios provide more torque multiplication but lower top speed.
GetWorldPosition(VehicleController)
Gets the world position of the transmission component.
Declaration
public override Vector3 GetWorldPosition(VehicleController vc)
Parameters
| Type | Name | Description |
|---|---|---|
| VehicleController | vc | The vehicle controller. |
Returns
| Type | Description |
|---|---|
| Vector3 | Transmission position in world space. |
Overrides
QueryAngularVelocity(float, float)
Queries and propagates angular velocity through the powertrain chain.
Declaration
public override float QueryAngularVelocity(float angularVelocity, float dt)
Parameters
| Type | Name | Description |
|---|---|---|
| float | angularVelocity | The input angular velocity in rad/s. |
| float | dt | The simulation delta time in seconds. |
Returns
| Type | Description |
|---|---|
| float | The final angular velocity after propagation through all connected components. |
Overrides
Remarks
Part of solver pass 1: propagates angular velocity from wheels toward engine. Returns input velocity unchanged if no output is connected.
QueryInertia(float)
Queries and accumulates inertia values through the powertrain chain.
Declaration
public override float QueryInertia(float DeltaTime)
Parameters
| Type | Name | Description |
|---|---|---|
| float | DeltaTime | The simulation delta time in seconds. |
Returns
| Type | Description |
|---|---|
| float | The total inertia of this component and all connected downstream components in kg⋅m². |
Overrides
Remarks
Adds this component's inertia to downstream components' accumulated inertia. Higher total inertia = slower acceleration, lower = more responsive.
QueryReturnTorque()
Queries the return torque (counterTorque) from downstream components after wheels have been stepped. Called after ForwardStep and wheel SubStep to get fresh counterTorque values.
Declaration
public override float QueryReturnTorque()
Returns
| Type | Description |
|---|---|
| float | The accumulated return torque from all downstream components. |
Overrides
RecalculateGearRatio(float)
Calculates the total gear ratio including transmission gear and final drive ratio.
Declaration
public void RecalculateGearRatio(float dt)
Parameters
| Type | Name | Description |
|---|---|---|
| float | dt |
Remarks
For standard transmissions: Returns gears[gearIndex] * finalGearRatio
For CVT transmissions: Calculates a variable ratio based on target RPM and wheel speed, providing infinite gear ratios within the min/max range specified in the gears list. The CVT ratio smoothly interpolates based on RPM and wheel speed.
ReverseTransmitRPM(float, int)
Converts axle RPM to engine RPM for the given gear in the Gears list.
Declaration
public float ReverseTransmitRPM(float inputRPM, int g)
Parameters
| Type | Name | Description |
|---|---|---|
| float | inputRPM | |
| int | g |
Returns
| Type | Description |
|---|---|
| float |
ShiftInto(int, bool)
Shifts into given gear. 0 for neutral, less than 0 for reverse and above 0 for forward gears. Does nothing if the target gear is equal to the current gear.
Declaration
public void ShiftInto(int targetGear, bool instant = false)
Parameters
| Type | Name | Description |
|---|---|---|
| int | targetGear | |
| bool | instant |
VC_Disable(bool)
Disables the powertrain component and resets its operational values.
Declaration
public override bool VC_Disable(bool calledByParent)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | calledByParent | True if this method was called by a parent component, false if called directly. |
Returns
| Type | Description |
|---|---|
| bool | True if the component was successfully disabled, false otherwise. |
Overrides
Remarks
When disabled, all angular velocity and torque values are reset to zero to ensure a clean state for the next time the component is enabled.
VC_Initialize()
Initializes the powertrain component and establishes connections with other components.
Declaration
protected override void VC_Initialize()
Overrides
Remarks
Called during vehicle initialization. Validates inertia and loads component connections from stored name hashes.
VC_SetDefaults()
Sets the component's properties to their default values.
Declaration
public override void VC_SetDefaults()
Overrides
Remarks
Sets inertia to 0.02 kg⋅m², suitable for most powertrain components.
VC_Validate(VehicleController)
Validates the powertrain component configuration and logs warnings for potential issues.
Declaration
public override void VC_Validate(VehicleController vc)
Parameters
| Type | Name | Description |
|---|---|---|
| VehicleController | vc | The vehicle controller that contains this component. |
Overrides
Remarks
Checks inertia minimum (0.0001) and output connections. Called during vehicle validation.