54 lines
1.1 KiB
C#
54 lines
1.1 KiB
C#
using Sandbox;
|
|
using Sandbox.VR;
|
|
using System;
|
|
using VeloX.Utils;
|
|
|
|
namespace VeloX;
|
|
|
|
|
|
public partial class VeloXCar
|
|
{
|
|
public bool ESCActive { get; private set; } = true;
|
|
public static bool UseESC = true;
|
|
private void UpdateESC()
|
|
{
|
|
ESCActive = false;
|
|
|
|
if ( !UseESC )
|
|
return;
|
|
|
|
if ( TotalSpeed < 100 || CarDirection != 1 )
|
|
return;
|
|
|
|
float angle = Body.Velocity.SignedAngle( WorldRotation.Forward, WorldRotation.Up ); ;
|
|
angle -= SteerAngle.yaw * 0.5f;
|
|
float absAngle = angle < 0 ? -angle : angle;
|
|
|
|
//foreach ( var wheel in Wheels )
|
|
//{
|
|
// if ( !wheel.IsOnGround )
|
|
// continue;
|
|
// Log.Info( wheel.LongitudinalSlip < 0.1f );
|
|
// if ( wheel.LongitudinalSlip < 0.1f )
|
|
// wheel.BrakeTorque += Math.Abs( wheel.LongitudinalSlip ) * 10000;
|
|
//}
|
|
|
|
if ( Engine.RevLimiterActive || absAngle < 2f )
|
|
return;
|
|
|
|
foreach ( var wheel in Wheels )
|
|
{
|
|
if ( !wheel.IsOnGround )
|
|
continue;
|
|
|
|
float additionalBrakeTorque = -angle * Math.Sign( wheel.LocalPosition.y ) * 20f;
|
|
if ( additionalBrakeTorque > 0 )
|
|
{
|
|
ESCActive = true;
|
|
wheel.BrakeTorque += additionalBrakeTorque;
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|