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