40 lines
670 B
C#
40 lines
670 B
C#
using Sandbox;
|
|
using System;
|
|
|
|
namespace VeloX;
|
|
|
|
|
|
public partial class VeloXCar
|
|
{
|
|
public bool TCSActive { get; private set; } = true;
|
|
public static bool UseTCS = true;
|
|
|
|
private void UpdateTCS()
|
|
{
|
|
TCSActive = false;
|
|
|
|
if ( !UseTCS )
|
|
return;
|
|
|
|
if ( TotalSpeed < 50 || CarDirection != 1 )
|
|
return;
|
|
|
|
float vehicleSpeed = TotalSpeed.InchToMeter();
|
|
|
|
foreach ( var wheel in Wheels )
|
|
{
|
|
if ( !wheel.IsOnGround )
|
|
continue;
|
|
|
|
float wheelLinearSpeed = wheel.AngularVelocity * wheel.Radius;
|
|
float wheelSlip = wheelLinearSpeed - vehicleSpeed;
|
|
|
|
if ( wheelSlip > 2.0f )
|
|
{
|
|
TCSActive = true;
|
|
wheel.BrakeTorque = wheelSlip * 1000;
|
|
}
|
|
}
|
|
}
|
|
}
|