dedicated
This commit is contained in:
@@ -15,7 +15,7 @@ public partial class VeloXCar
|
||||
if ( !UseABS )
|
||||
return;
|
||||
|
||||
if ( TotalSpeed < 100 || Steering.AlmostEqual( 0, 1 ) )
|
||||
if ( TotalSpeed < 100 || SteeringAngle.AlmostEqual( 0, 1 ) )
|
||||
return;
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
|
||||
|
||||
using Sandbox;
|
||||
using Sandbox.Audio;
|
||||
using System;
|
||||
|
||||
namespace VeloX;
|
||||
@@ -48,23 +49,27 @@ public partial class VeloXCar
|
||||
|
||||
protected virtual void UpdateDrift( float dt )
|
||||
{
|
||||
float driftAngle = GetDriftAngle();
|
||||
|
||||
float mul = (driftAngle - MIN_DRIFT_ANGLE) / (90 - MIN_DRIFT_ANGLE);
|
||||
var avgslip = 0f;
|
||||
foreach ( var item in Wheels )
|
||||
avgslip += item.NormalizedLongitudinalSlip + item.NormalizedLateralSlip;
|
||||
|
||||
if ( !_skidHandle.IsValid() )
|
||||
_skidHandle = Sound.PlayFile( SkidSound );
|
||||
|
||||
if ( !_skidHandle.IsValid() )
|
||||
return;
|
||||
float mul = Math.Clamp( avgslip, 0, 2 );
|
||||
|
||||
targetVolume = mul;
|
||||
targetPitch = 0.75f + 0.25f * mul;
|
||||
|
||||
if ( mul > 0.1f && !_skidHandle.IsValid() )
|
||||
{
|
||||
_skidHandle = Sound.PlayFile( SkidSound );
|
||||
_skidHandle.TargetMixer = Mixer.Default;
|
||||
}
|
||||
|
||||
if ( !_skidHandle.IsValid() )
|
||||
return;
|
||||
|
||||
_skidHandle.Pitch += (targetPitch - _skidHandle.Pitch) * dt * 5f;
|
||||
_skidHandle.Volume += (targetVolume - _skidHandle.Volume) * dt * 10f;
|
||||
_skidHandle.Position = WorldPosition;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,15 +24,6 @@ public partial class VeloXCar
|
||||
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;
|
||||
|
||||
|
||||
@@ -21,16 +21,11 @@ public partial class VeloXCar
|
||||
public int CarDirection { get { return ForwardSpeed < 1 ? 0 : (VelocityAngle < 90 && VelocityAngle > -90 ? 1 : -1); } }
|
||||
public float VelocityAngle { get; private set; }
|
||||
|
||||
[Sync] public float Steering { get; private set; }
|
||||
|
||||
private float currentSteerAngle;
|
||||
private float inputSteer;
|
||||
private void UpdateSteering( float dt )
|
||||
{
|
||||
inputSteer = Input.AnalogMove.y;
|
||||
|
||||
|
||||
float targetSteerAngle = inputSteer * MaxSteerAngle;
|
||||
float targetSteerAngle = SteeringAngle * MaxSteerAngle;
|
||||
|
||||
if ( !Input.Down( "Jump" ) )
|
||||
targetSteerAngle *= Math.Clamp( 1 - Math.Clamp( TotalSpeed / 3000, 0f, 0.85f ), -1, 1 );
|
||||
@@ -42,10 +37,9 @@ public partial class VeloXCar
|
||||
if ( TotalSpeed > 150 && CarDirection > 0 && IsOnGround )
|
||||
targetAngle = VelocityAngle * MaxSteerAngleMultiplier;
|
||||
|
||||
float lerpSpeed = Math.Abs( inputSteer ) < 0.1f ? SteerReturnSpeed : SteerInputResponse;
|
||||
float lerpSpeed = Math.Abs( SteeringAngle ) < 0.1f ? SteerReturnSpeed : SteerInputResponse;
|
||||
|
||||
currentSteerAngle = ExpDecay( currentSteerAngle, targetSteerAngle, lerpSpeed, Time.Delta );
|
||||
Steering = currentSteerAngle + targetAngle;
|
||||
SteerAngle = new( 0, Math.Clamp( Steering, -MaxSteerAngle, MaxSteerAngle ), 0 );
|
||||
SteerAngle = new( 0, Math.Clamp( currentSteerAngle + targetAngle, -MaxSteerAngle, MaxSteerAngle ), 0 );
|
||||
}
|
||||
}
|
||||
|
||||
39
Code/Car/VeloXCar.TCS.cs
Normal file
39
Code/Car/VeloXCar.TCS.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ public partial class VeloXCar : VeloXBase
|
||||
return;
|
||||
UpdateABS();
|
||||
UpdateESC();
|
||||
UpdateTCS();
|
||||
var dt = Time.Delta;
|
||||
//EngineThink( dt );
|
||||
SimulateAerodinamics( dt );
|
||||
@@ -26,7 +27,7 @@ public partial class VeloXCar : VeloXBase
|
||||
|
||||
private void UpdateUnflip( float dt )
|
||||
{
|
||||
if ( Math.Abs( inputSteer ) < 0.1f )
|
||||
if ( Math.Abs( SteeringAngle ) < 0.1f )
|
||||
return;
|
||||
|
||||
if ( IsOnGround || Math.Abs( WorldRotation.Roll() ) < 60 )
|
||||
@@ -42,7 +43,7 @@ public partial class VeloXCar : VeloXBase
|
||||
if ( velocityFactor <= 0.01f )
|
||||
return;
|
||||
|
||||
var force = inputSteer * velocityFactor * 150;
|
||||
var force = SteeringAngle * velocityFactor * 150;
|
||||
|
||||
Body.AngularVelocity -= Body.WorldRotation.Forward * force * dt;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user