Guest User

Untitled

a guest
Nov 1st, 2025
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.56 KB | None | 0 0
  1. // EDITED VERSION || :: SLIP RATIO CALCULATION :: | ASYMMETRIC | SAE J670 STANDARD |
  2. void UFGearWheel::updateSlipValues()
  3. {
  4.     if (!mHasContact) {mLateralSlip = mLongitudinalSlip = mSlipRatio = mSlipAngle = 0.0f; return;}
  5.  
  6.     // === 1. WHEEL LINEAR SPEED (REAL, FROM DRIVETRAIN) === |
  7.     float wheelSpeed = mRealSpeed *mRadius;  // rad/s * m = m/s
  8.  
  9.     // === 2. LONGITUDINAL SLIP VELOCITY === |
  10.     mLongitudinalSlip = wheelSpeed -mLocalVelocity.X; // mLocalVelocity.X = m/s
  11.    
  12.     // === 3. OVERRIDE (Disabled) === || OFF = Full throtle + Brake = Car barely moves if BrakeTorque high = Realistic.
  13.     // Hack/Breaks Realism = Ignores real wheel spin & force slipRatio to peak grip value when ASR/ABS is active.
  14.     // NOTE: Posible bugs causing: Due overrides real slip > jitter, lockup...
  15.     // NOTE: May contribute to small fast impulses after drop brake if full throttle
  16.     // if (FMath::Abs(mLongitudinalSlip) < FMath::Abs(mLngSlipOverride)) mLongitudinalSlip = mLngSlipOverride;
  17.    
  18.     // === 4. SLIP RATIO CALCULATION | ASYMMETRIC | SAE J670 STANDARD  === |
  19.     float absForwardVelocity = FMath::Abs(mLocalVelocity.X);
  20.     float absWheelSpeed      = FMath::Abs(wheelSpeed);
  21.  
  22.     // Ternary version with V_MIN (For +stable values)
  23.     float V_MIN = 0.05f;      // Def:0.05 (~0.18 km/h)
  24.     float denom = (absWheelSpeed > absForwardVelocity)
  25.     ? FMath::Max(absWheelSpeed,      V_MIN)   // accel
  26.     : FMath::Max(absForwardVelocity, V_MIN);  // brake
  27.     mSlipRatio = mLongitudinalSlip / denom;
  28.    
  29.     // ------------------------------------------------------------
  30.  
  31.     // === LATERAL SLIP === |
  32.     mLateralSlip = -mLocalVelocity.Y;
  33.    
  34.     // === SLIP ANGLE === |
  35.     mSlipAngle = FMath::Atan(mLocalVelocity.Y / (absForwardVelocity + FGearUtility::epsilon)); // Original
  36.     // No need V_MIN | Wrong physics > Slip angle is geometric, not filtered like slip ratio
  37.     // >> At low speed, Vx = 0.01 ? denom = 0.05 ? forces artificial forward motion
  38.     // >> Breaks steering at standstill > Car should turn in place ? a = ±90° if Vx = 0
  39.  
  40.     // *** TESTING :: atan2 || 2–3x slower | May need profiling
  41.     // FMath::Atan(y / x) can be unstable for small x. Use FMath::Atan2(y, x) (handles sign/quadrant and zero nicely).
  42.     // atan() generally less useful in gamedev, can't handle correct quadrant + prone to division-by-zero errors
  43.     // mSlipAngle = FMath::Atan2(mLocalVelocity.Y, absForwardVelocity); // No epsilon needed, atan2 handles 0 perfectly
  44.  
  45.  
  46.     // === CLAMP === |
  47.     mSlipRatio = FMath::Clamp(mSlipRatio, -1.0f, 1.0f);
  48.     mSlipAngle = FMath::Clamp(mSlipAngle, -0.475f * PI, 0.475f * PI);
  49. }
Advertisement
Add Comment
Please, Sign In to add comment