new pacejka implementation (car not working)
This commit is contained in:
@@ -3,7 +3,7 @@ using System;
|
||||
|
||||
namespace VeloX.Powertrain;
|
||||
|
||||
[Category( "VeloX/Powertrain/Gearbox" )]
|
||||
[Category( "VeloX/Powertrain/Differential" )]
|
||||
public abstract class BaseDifferential : PowertrainComponent
|
||||
{
|
||||
[Property] public float FinalDrive { get; set; } = 3.392f;
|
||||
|
||||
@@ -8,8 +8,6 @@ public class Engine : PowertrainComponent
|
||||
[Property, Group( "Settings" )] public float IdleRPM { get; set; } = 900f;
|
||||
[Property, Group( "Settings" )] public float MaxRPM { get; set; } = 7000f;
|
||||
[Property, Group( "Settings" )] public override float Inertia { get; set; } = 0.151f;
|
||||
[Property, Group( "Settings" )] public float StartFriction { get; set; } = 50f;
|
||||
[Property, Group( "Settings" )] public float FrictionCoeff { get; set; } = 0.02f;
|
||||
[Property, Group( "Settings" )] public float LimiterDuration { get; set; } = 0.05f;
|
||||
[Property, Group( "Settings" )] public Curve TorqueMap { get; set; }
|
||||
[Property, Group( "Settings" )] public EngineStream Stream { get; set; }
|
||||
@@ -24,6 +22,7 @@ public class Engine : PowertrainComponent
|
||||
private float finalTorque;
|
||||
|
||||
private EngineStreamPlayer StreamPlayer;
|
||||
public float[] friction = [15.438f, 2.387f, 0.7958f];
|
||||
|
||||
protected override void OnStart()
|
||||
{
|
||||
@@ -32,11 +31,19 @@ public class Engine : PowertrainComponent
|
||||
StreamPlayer = new( Stream );
|
||||
}
|
||||
|
||||
public float GetFrictionTorque( float throttle, float rpm )
|
||||
{
|
||||
float s = rpm < 0 ? -1f : 1f;
|
||||
float r = s * rpm * 0.001f;
|
||||
float f = friction[0] + friction[1] * r + friction[2] * r * r;
|
||||
return -s * f * (1 - throttle);
|
||||
}
|
||||
private float GenerateTorque()
|
||||
{
|
||||
float throttle = Throttle;
|
||||
float rpm = RPM;
|
||||
float friction = StartFriction - rpm * FrictionCoeff;
|
||||
float friction = GetFrictionTorque( throttle, rpm );
|
||||
|
||||
float maxInitialTorque = TorqueMap.Evaluate( RPMPercent ) - friction;
|
||||
float idleFadeStart = Math.Clamp( MathX.Remap( rpm, IdleRPM - 300, IdleRPM, 1, 0 ), 0, 1 );
|
||||
float idleFadeEnd = Math.Clamp( MathX.Remap( rpm, IdleRPM, IdleRPM + 600, 1, 0 ), 0, 1 );
|
||||
@@ -70,6 +77,7 @@ public class Engine : PowertrainComponent
|
||||
float outputInertia = Output.QueryInertia();
|
||||
float inertiaSum = Inertia + outputInertia;
|
||||
float outputW = Output.QueryAngularVelocity( angularVelocity );
|
||||
|
||||
float targetW = Inertia / inertiaSum * angularVelocity + outputInertia / inertiaSum * outputW;
|
||||
float generatedTorque = GenerateTorque();
|
||||
float reactTorque = (targetW - angularVelocity) * Inertia / Time.Delta;
|
||||
|
||||
Reference in New Issue
Block a user