53 lines
1.1 KiB
C#
53 lines
1.1 KiB
C#
using Sandbox;
|
|
|
|
namespace VeloX.Powertrain;
|
|
|
|
public class ManualGearbox : BaseGearbox
|
|
{
|
|
[Property] public float[] Ratios { get; set; } = [3.626f, 2.200f, 1.541f, 1.213f, 1.000f, 0.767f];
|
|
[Property] public float Reverse { get; set; } = 3.4f;
|
|
[Property, InputAction] public string ForwardAction { get; set; } = "Attack1";
|
|
[Property, InputAction] public string BackwardAction { get; set; } = "Attack2";
|
|
|
|
private int gear;
|
|
|
|
protected void SetGear( int gear )
|
|
{
|
|
if ( gear < -1 || gear >= Ratios.Length )
|
|
return;
|
|
this.gear = gear;
|
|
|
|
RecalcRatio();
|
|
}
|
|
|
|
private void RecalcRatio()
|
|
{
|
|
if ( gear == -1 )
|
|
ratio = -Reverse;
|
|
else if ( gear == 0 )
|
|
ratio = 0;
|
|
else
|
|
ratio = Ratios[gear - 1];
|
|
}
|
|
|
|
public void Shift( int dir )
|
|
{
|
|
SetGear( gear + dir );
|
|
}
|
|
|
|
private void InputResolve()
|
|
{
|
|
if ( Sandbox.Input.Pressed( ForwardAction ) )
|
|
Shift( 1 );
|
|
else if ( Sandbox.Input.Pressed( BackwardAction ) )
|
|
Shift( -1 );
|
|
}
|
|
|
|
public override float ForwardStep( float torque, float inertia )
|
|
{
|
|
InputResolve();
|
|
|
|
return base.ForwardStep( torque, inertia );
|
|
}
|
|
}
|