cleanup code
This commit is contained in:
parent
f0f89ff947
commit
55a178e8c5
@ -151,15 +151,6 @@ public partial class VeloXWheel : Component
|
||||
|
||||
var vel = vehicle.Body.GetVelocityAtPoint( contactPos );
|
||||
|
||||
//var vel = vehicle.Body.GetVelocityAtPoint( pos );
|
||||
|
||||
if ( !IsOnGround )
|
||||
{
|
||||
forwardFriction = new Friction();
|
||||
sideFriction = new Friction();
|
||||
return;
|
||||
}
|
||||
|
||||
var offset = maxLen - (fraction * maxLen);
|
||||
var springForce = (offset * SpringStrength);
|
||||
var damperForce = (lastSpringOffset - offset) * SpringDamper;
|
||||
@ -194,71 +185,65 @@ public partial class VeloXWheel : Component
|
||||
|
||||
load = Math.Max( force.z, 0 ).InchToMeter();
|
||||
|
||||
float forwardSpeed = vel.Dot( forward ).InchToMeter();
|
||||
float sideSpeed = vel.Dot( right ).InchToMeter();
|
||||
|
||||
float camber_rad = CamberAngle.DegreeToRadian();
|
||||
float R = Radius.InchToMeter();
|
||||
|
||||
float linearSpeed = angularVelocity * Radius.InchToMeter();
|
||||
|
||||
float F_roll = TirePreset.GetRollingResistance( linearSpeed, 1.0f );
|
||||
F_roll *= -Math.Clamp( linearSpeed * 0.25f, -1, 1 );
|
||||
|
||||
float T_brake = Brake * BrakePowerMax;
|
||||
T_brake *= -Math.Clamp( linearSpeed * 0.25f, -1, 1 );
|
||||
|
||||
float Winit = angularVelocity;
|
||||
|
||||
angularVelocity += F_roll * 9.80665f / Inertia * Time.Delta;
|
||||
|
||||
angularVelocity += Torque / Inertia * Time.Delta;
|
||||
|
||||
|
||||
angularVelocity += T_brake / Inertia * Time.Delta;
|
||||
|
||||
if ( IsOnGround )
|
||||
{
|
||||
float forwardSpeed = vel.Dot( forward ).InchToMeter();
|
||||
float sideSpeed = vel.Dot( right ).InchToMeter();
|
||||
|
||||
float camber_rad = CamberAngle.DegreeToRadian();
|
||||
float R = Radius.InchToMeter();
|
||||
|
||||
//TirePreset.ComputeState(
|
||||
// load,
|
||||
// angularVelocity,
|
||||
// forwardSpeed,
|
||||
// sideSpeed,
|
||||
// camber_rad,
|
||||
// R,
|
||||
// Inertia,
|
||||
// out var tireState
|
||||
//);
|
||||
|
||||
float linearSpeed = angularVelocity * Radius.InchToMeter();
|
||||
float F_roll = TirePreset.GetRollingResistance( linearSpeed, 1.0f );
|
||||
F_roll *= -Math.Clamp( linearSpeed * 0.25f, -1, 1 );
|
||||
|
||||
//float Fx_total = tireState.fx + F_roll;
|
||||
|
||||
float T_brake = Brake * BrakePowerMax;
|
||||
|
||||
if ( angularVelocity > 0 ) T_brake = -T_brake;
|
||||
else T_brake = angularVelocity < 0 ? T_brake : -MathF.Sign( Torque ) * T_brake;
|
||||
//float totalTorque = Torque + tireState.fx;
|
||||
|
||||
angularVelocity += Torque / Inertia * Time.Delta;
|
||||
angularVelocity += T_brake / Inertia * Time.Delta;
|
||||
angularVelocity += F_roll * 9.80665f / Inertia * Time.Delta;
|
||||
TirePreset.ComputeSlip( forwardSpeed, sideSpeed, angularVelocity, R, out var slip, out var slip_ang );
|
||||
var fx = TirePreset.Pacejka.PacejkaFx( slip, load, 1, out var maxTorque );
|
||||
var fy = TirePreset.Pacejka.PacejkaFy( slip_ang * load, load, camber_rad, 1, out var _ );
|
||||
|
||||
maxTorque *= R;
|
||||
var errorTorque = (angularVelocity - forwardSpeed / R) * Inertia / Time.Delta;
|
||||
var errorTorque = (angularVelocity - forwardSpeed / R) * BaseInertia / Time.Delta;
|
||||
|
||||
var surfaceTorque = Math.Clamp( errorTorque, -maxTorque, maxTorque );
|
||||
|
||||
angularVelocity -= surfaceTorque / Inertia * Time.Delta;
|
||||
|
||||
forwardFriction = new Friction()
|
||||
{
|
||||
Slip = slip,
|
||||
Force = -fx,
|
||||
Speed = forwardSpeed
|
||||
};
|
||||
|
||||
sideFriction = new Friction()
|
||||
{
|
||||
Slip = slip_ang,
|
||||
Force = fy,
|
||||
Speed = sideSpeed
|
||||
};
|
||||
float deltaOmegaTorque = (angularVelocity - Winit) * Inertia / Time.Delta;
|
||||
|
||||
Vector3 frictionForce = forward * forwardFriction.Force + right * sideFriction.Force;
|
||||
CounterTorque = -surfaceTorque - deltaOmegaTorque;
|
||||
forwardFriction.Slip = slip;
|
||||
forwardFriction.Force = -fx;
|
||||
forwardFriction.Speed = forwardSpeed;
|
||||
sideFriction.Slip = slip_ang;
|
||||
sideFriction.Force = fy;
|
||||
sideFriction.Speed = sideSpeed;
|
||||
|
||||
vehicle.Body.ApplyForceAt( pos, force / Time.Delta * ProjectSettings.Physics.SubSteps );
|
||||
vehicle.Body.ApplyForceAt( pos, frictionForce * ProjectSettings.Physics.SubSteps );
|
||||
|
||||
Vector3 frictionForce = forward * forwardFriction.Force + right * sideFriction.Force;
|
||||
vehicle.Body.ApplyForceAt( pos, frictionForce * ProjectSettings.Physics.SubSteps );
|
||||
}
|
||||
else
|
||||
{
|
||||
forwardFriction = new();
|
||||
sideFriction = new();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -298,8 +283,8 @@ public partial class VeloXWheel : Component
|
||||
// debug
|
||||
protected override void OnUpdate()
|
||||
{
|
||||
DebugOverlay.Normal( contactPos, forward * forwardFriction.Force / 1000f, Color.Red, overlay: true );
|
||||
DebugOverlay.Normal( contactPos, right * sideFriction.Force / 1000f, Color.Green, overlay: true );
|
||||
DebugOverlay.Normal( contactPos, up * force / 1000f, Color.Blue, overlay: true );
|
||||
//DebugOverlay.Normal( contactPos, forward * forwardFriction.Force / 1000f, Color.Red, overlay: true );
|
||||
//DebugOverlay.Normal( contactPos, right * sideFriction.Force / 1000f, Color.Green, overlay: true );
|
||||
//DebugOverlay.Normal( contactPos, up * force / 1000f, Color.Blue, overlay: true );
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user