update
This commit is contained in:
@@ -543,13 +543,14 @@ public class Transmission : PowertrainComponent
|
||||
// Run the first half of shift timer
|
||||
float shiftTimer = 0;
|
||||
float halfDuration = ShiftDuration * 0.5f;
|
||||
if ( !instant )
|
||||
while ( shiftTimer < halfDuration )
|
||||
{
|
||||
ShiftProgress = shiftTimer / ShiftDuration;
|
||||
shiftTimer += dt;
|
||||
await Task.DelayRealtimeSeconds( dt );
|
||||
}
|
||||
|
||||
//if ( !instant )
|
||||
// while ( shiftTimer < halfDuration )
|
||||
// {
|
||||
// ShiftProgress = shiftTimer / ShiftDuration;
|
||||
// shiftTimer += dt;
|
||||
// await Task.DelayRealtimeSeconds( dt );
|
||||
// }
|
||||
|
||||
// Do the shift at the half point of shift duration
|
||||
Gear = targetGear;
|
||||
@@ -603,28 +604,28 @@ public class Transmission : PowertrainComponent
|
||||
float brakeInput = car.SwappedBrakes;
|
||||
int currentGear = Gear;
|
||||
// Assign base shift points
|
||||
_targetDownshiftRPM = _downshiftRPM;
|
||||
_targetUpshiftRPM = _upshiftRPM;
|
||||
|
||||
_targetDownshiftRPM = car.Engine.EstimatedPeakPowerRPM - 2000;
|
||||
_targetUpshiftRPM = car.Engine.EstimatedPeakPowerRPM;
|
||||
|
||||
// Calculate shift points for variable shift RPM
|
||||
if ( VariableShiftPoint )
|
||||
{
|
||||
// Smooth throttle input so that the variable shift point does not shift suddenly and cause gear hunting
|
||||
_smoothedThrottleInput = MathX.Lerp( _smoothedThrottleInput, throttleInput, Time.Delta * 2f );
|
||||
float revLimiterRPM = car.Engine.RevLimiterRPM;
|
||||
//if ( VariableShiftPoint )
|
||||
//{
|
||||
// // Smooth throttle input so that the variable shift point does not shift suddenly and cause gear hunting
|
||||
// _smoothedThrottleInput = MathX.Lerp( _smoothedThrottleInput, throttleInput, Time.Delta * 2f );
|
||||
// float revLimiterRPM = car.Engine.RevLimiterRPM;
|
||||
|
||||
_targetUpshiftRPM = _upshiftRPM + Math.Clamp( _smoothedThrottleInput * VariableShiftIntensity, 0f, 1f ) * _upshiftRPM;
|
||||
_targetUpshiftRPM = Math.Clamp( _targetUpshiftRPM, _upshiftRPM, revLimiterRPM * 0.97f );
|
||||
// _targetUpshiftRPM = _upshiftRPM + Math.Clamp( _smoothedThrottleInput * VariableShiftIntensity, 0f, 1f ) * _upshiftRPM;
|
||||
// _targetUpshiftRPM = Math.Clamp( _targetUpshiftRPM, _upshiftRPM, revLimiterRPM * 0.97f );
|
||||
|
||||
_targetDownshiftRPM = _downshiftRPM + Math.Clamp( _smoothedThrottleInput * VariableShiftIntensity, 0f, 1f ) * _downshiftRPM;
|
||||
_targetDownshiftRPM = Math.Clamp( _targetDownshiftRPM, car.Engine.IdleRPM * 1.1f, _targetUpshiftRPM * 0.7f );
|
||||
// _targetDownshiftRPM = _downshiftRPM + Math.Clamp( _smoothedThrottleInput * VariableShiftIntensity, 0f, 1f ) * _downshiftRPM;
|
||||
// _targetDownshiftRPM = Math.Clamp( _targetDownshiftRPM, car.Engine.IdleRPM * 1.1f, _targetUpshiftRPM * 0.7f );
|
||||
|
||||
// Add incline modifier
|
||||
float inclineModifier = Math.Clamp( car.WorldRotation.Forward.Dot( Vector3.Up ) * InclineEffectCoeff, 0f, 1f );
|
||||
// // Add incline modifier
|
||||
// float inclineModifier = Math.Clamp( car.WorldRotation.Forward.Dot( Vector3.Up ) * InclineEffectCoeff, 0f, 1f );
|
||||
|
||||
_targetUpshiftRPM += revLimiterRPM * inclineModifier;
|
||||
_targetDownshiftRPM += revLimiterRPM * inclineModifier;
|
||||
}
|
||||
// _targetUpshiftRPM += revLimiterRPM * inclineModifier;
|
||||
// _targetDownshiftRPM += revLimiterRPM * inclineModifier;
|
||||
//}
|
||||
|
||||
|
||||
// In neutral
|
||||
|
||||
@@ -59,7 +59,7 @@ public abstract partial class VeloXBase
|
||||
/// Throttle axis.
|
||||
/// For combined throttle/brake input use 'VerticalInput' instead.
|
||||
/// </summary>
|
||||
[Sync( SyncFlags.Interpolate ), Range( 0, 1 ), Property]
|
||||
[Sync( SyncFlags.Interpolate ), Range( 0, 1 ), Property, ReadOnly]
|
||||
public float Throttle
|
||||
{
|
||||
get => throttle;
|
||||
@@ -70,19 +70,20 @@ public abstract partial class VeloXBase
|
||||
/// Brake axis.
|
||||
/// For combined throttle/brake input use 'VerticalInput' instead.
|
||||
/// </summary>
|
||||
[Sync]
|
||||
[Range( 0, 1 ), Property, ReadOnly]
|
||||
public float Brakes
|
||||
{
|
||||
get => brakes;
|
||||
set => brakes = Math.Clamp( value, 0, 1 );
|
||||
}
|
||||
|
||||
[Sync]
|
||||
[Sync( SyncFlags.Interpolate ), Range( 0, 1 ), Property, ReadOnly]
|
||||
public float SteeringAngle
|
||||
{
|
||||
get => steerAngle;
|
||||
set => steerAngle = Math.Clamp( value, -1, 1 );
|
||||
}
|
||||
|
||||
[Sync]
|
||||
public float Handbrake
|
||||
{
|
||||
@@ -103,7 +104,7 @@ public abstract partial class VeloXBase
|
||||
IsShiftingUp = false;
|
||||
IsShiftingDown = false;
|
||||
}
|
||||
private void UpdateInput()
|
||||
protected void UpdateInput()
|
||||
{
|
||||
VerticalInput = Input.AnalogMove.x;
|
||||
Handbrake = Input.Down( "Handbrake" ) ? 1 : 0;
|
||||
|
||||
@@ -7,9 +7,9 @@ public abstract partial class VeloXBase
|
||||
|
||||
private Vector3 linForce;
|
||||
private Vector3 angForce;
|
||||
[Property] float BrakeForce { get; set; } = 1500f;
|
||||
[Property] float HandbrakeForce { get; set; } = 3500f;
|
||||
private void PhysicsSimulate()
|
||||
protected const float BrakeForce = 4500f;
|
||||
protected const float HandbrakeForce = 35000f;
|
||||
protected void PhysicsSimulate()
|
||||
{
|
||||
if ( Body.Sleeping && Input.AnalogMove.x == 0 )
|
||||
return;
|
||||
@@ -36,10 +36,22 @@ public abstract partial class VeloXBase
|
||||
CombinedLoad += v.Fz;
|
||||
foreach ( var v in Wheels )
|
||||
{
|
||||
v.BrakeTorque = SwappedBrakes * BrakeForce;
|
||||
if ( !v.IsFront )
|
||||
if ( v.IsFront )
|
||||
{
|
||||
v.BrakeTorque = SwappedBrakes * BrakeForce * 1.3f;
|
||||
}
|
||||
else
|
||||
{
|
||||
v.BrakeTorque = SwappedBrakes * BrakeForce * 0.7f;
|
||||
v.BrakeTorque += Handbrake * HandbrakeForce;
|
||||
|
||||
}
|
||||
|
||||
if ( TotalSpeed < 1 && Input.AnalogMove.x == 0 )
|
||||
{
|
||||
v.BrakeTorque = HandbrakeForce;
|
||||
}
|
||||
|
||||
v.Update( this, in dt );
|
||||
v.DoPhysics( in dt );
|
||||
}
|
||||
|
||||
@@ -30,9 +30,14 @@ public abstract partial class VeloXBase : Component
|
||||
TotalSpeed = LocalVelocity.Length;
|
||||
Body.PhysicsBody.Mass = Mass;
|
||||
|
||||
FixedUpdate();
|
||||
}
|
||||
|
||||
protected virtual void FixedUpdate()
|
||||
{
|
||||
|
||||
UpdateInput();
|
||||
PhysicsSimulate();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public partial class VeloXWheel
|
||||
/// </summary>
|
||||
public float CounterTorque { get; private set; }
|
||||
|
||||
[Property, Range( 0, 2 )] public float BrakeMult { get; set; } = 1f;
|
||||
//[Property, Range( 0, 2 )] public float BrakeMult { get; set; } = 1f;
|
||||
public Friction ForwardFriction = new();
|
||||
public Friction SidewayFriction = new();
|
||||
public Vector3 FrictionForce;
|
||||
@@ -100,7 +100,7 @@ public partial class VeloXWheel
|
||||
private void UpdateFriction( float dt )
|
||||
{
|
||||
var motorTorque = DriveTorque;
|
||||
var brakeTorque = BrakeTorque * BrakeMult;
|
||||
var brakeTorque = BrakeTorque;
|
||||
|
||||
float allWheelLoadSum = Vehicle.CombinedLoad;
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ internal sealed class WheelManager : GameObjectSystem
|
||||
|
||||
private void UpdateWheels()
|
||||
{
|
||||
if ( !Game.IsPlaying )
|
||||
if ( !Game.IsPlaying || Scene.IsEditor )
|
||||
return;
|
||||
//Stopwatch sw = Stopwatch.StartNew();
|
||||
|
||||
@@ -38,7 +38,7 @@ internal sealed class WheelManager : GameObjectSystem
|
||||
}
|
||||
private void UpdateEngine()
|
||||
{
|
||||
if ( !Game.IsPlaying )
|
||||
if ( !Game.IsPlaying || Scene.IsEditor )
|
||||
return;
|
||||
//Stopwatch sw = Stopwatch.StartNew();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user