Class GearBox
This class is used to create a gearbox for a vehicle, it is used by the CarEngineController class but you can use it to create your own gearbox for your custom car controller. It supports automatic shifting, neutral and reverse gears. Refer to the constructor below for more information on how to initialize a gearbox.
Namespace: YACC
Assembly: .dll
Syntax
[Serializable]
public class GearBox
Constructors
Name | Description |
---|---|
GearBox(float[], float, float, float) | Initializes a new instance of the GearBox class. |
Fields
Name | Description |
---|---|
automaticShift | Tick this to enable automatic shifting. |
changeGearTime | The time the gear box will take to change gears (in seconds). |
currentGear | Current gear in the gearbox, the property can be set and retrieved although it is suggested to use the GetGear() and ChangeGear() methods instead. |
finalRatio | The final drive ratio is the last bit of gearing between your transmission and the driven wheels. Changing it can dramatically affect your car's performance. A lower ratio leads to less torque at the wheels but a higher top speed, while a higher ratio results in more torque at the wheels but a lower top speed. This is done without any change to the power and torque of the engine. |
gears | List of gears within the Gear box. The exposed list is used to set the gear ratios in the inspector. |
reverseRatio | The gear ratio for the reverse in the gear box, usually this value is very close to the 1st gear as the car needs to accelerate backwards usually from a standstill. |
state | Current state of the gearbox, refer to the GearState enum for more information. |
Properties
Name | Description |
---|---|
clutch | Clutch in the gear box, values are from 0 meaning the gearbox is detached from the engine to 1 meaning the clutch is fully engaged. |
Methods
Name | Description |
---|---|
ChangeGear(int) | Shifts the gear box to the desired gear. -1 and 0 are reserved for reverse and neutral respectively. |
GetCurrentGear() | Retrieves the current gear as a string, this is useful for displaying the current gear in a UI. |
GetGear(int?) | Returns the current or specified Gear instance. |
GetGearRatio(int?) | Returns the gear ratio multiplied with the final drive ratio, this is the ratio used to calculate the torque to apply on the engine. |
NeedsShiftDown(float, float) | Check if the current speed and RPM are below the threshold required to shift down the gear box. Used for automatic shifting, or to check if the car needs to shift up for assisted manual shifting. |
NeedsShiftUp(float, float) | Check if the current speed and RPM are above the threshold required to shift up the gear box. Used for automatic shifting, or to check if the car needs to shift up for assisted manual shifting. |
OnValidate() | Validates all fields, clamps all ratios. Make sure to call this method from your OnValidate method. |
ShiftDown() | Shifts the gear box down. Note that this will not shift into reverse from neutral gear.
|
ShiftUp() | Shifts the gear box up. ShiftUp() will take care about the appropriate checks for you and won't shift your gear up if you are already in the highest gear. |