update
This commit is contained in:
38
Code/Car/VeloXCar.ABS.cs
Normal file
38
Code/Car/VeloXCar.ABS.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using Sandbox;
|
||||
using System;
|
||||
|
||||
namespace VeloX;
|
||||
|
||||
|
||||
public partial class VeloXCar
|
||||
{
|
||||
public bool ABSActive { get; private set; } = true;
|
||||
public static bool UseABS = true;
|
||||
|
||||
private void UpdateABS()
|
||||
{
|
||||
if ( !UseABS )
|
||||
return;
|
||||
|
||||
ABSActive = false;
|
||||
|
||||
if ( TotalSpeed < 100 || ABSActive )
|
||||
return;
|
||||
|
||||
|
||||
if ( Brakes == 0 || CarDirection != 1 || Engine.RevLimiterActive || Handbrake >= 0.1f )
|
||||
return;
|
||||
foreach ( var wheel in Wheels )
|
||||
{
|
||||
if ( !wheel.IsOnGround )
|
||||
continue;
|
||||
|
||||
if ( wheel.NormalizedLongitudinalSlip >= 0.55f )
|
||||
{
|
||||
ABSActive = true;
|
||||
wheel.BrakeTorque *= 0.25f;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
44
Code/Car/VeloXCar.ESC.cs
Normal file
44
Code/Car/VeloXCar.ESC.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
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()
|
||||
{
|
||||
if ( !UseESC )
|
||||
return;
|
||||
ESCActive = false;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,7 +33,7 @@ public partial class VeloXCar
|
||||
float targetSteerAngle = inputSteer * MaxSteerAngle;
|
||||
|
||||
if ( !Input.Down( "Jump" ) )
|
||||
targetSteerAngle *= Math.Clamp( 1 - Math.Clamp( TotalSpeed / 3000, 0.01f, 0.9f ), -1, 1 );
|
||||
targetSteerAngle *= Math.Clamp( 1 - Math.Clamp( TotalSpeed / 3000, 0f, 0.85f ), -1, 1 );
|
||||
|
||||
VelocityAngle = -Body.Velocity.SignedAngle( WorldRotation.Forward, WorldRotation.Up );
|
||||
|
||||
|
||||
@@ -8,6 +8,15 @@ namespace VeloX;
|
||||
public partial class VeloXCar : VeloXBase
|
||||
{
|
||||
|
||||
protected override void FixedUpdate()
|
||||
{
|
||||
|
||||
UpdateInput();
|
||||
PhysicsSimulate();
|
||||
UpdateABS();
|
||||
UpdateESC();
|
||||
}
|
||||
|
||||
protected override void OnFixedUpdate()
|
||||
{
|
||||
if ( IsProxy )
|
||||
|
||||
Reference in New Issue
Block a user