Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Returns the speed (m/s) you should be going at, given a distance (m) to the target,
- //the target speed (m/s) at distance Zero and a theoretical max deceleration (m/s^2)
- public static float MapIdealSpeedForDistanceG(Racer r, float distance, float speedThere)
- {
- //Absolute minimum
- if (distance <= 0f) return speedThere;
- //Math variables
- float targetDistance = distance;
- if (targetDistance < 0f) targetDistance = 0f;
- float velCurrent = r.Car.Velocity.Length();
- float velTarget = speedThere;
- float timeToReachTarget = targetDistance / velCurrent;
- //Braking ability has to account for at least 25% of the wheel grip to count as fully taking advantage of the grip. Else, braking Gs are less than grip Gs
- float brakingAbility = (float)Math.Round(ARS.map(ARS.GetPercent(r.handlingData.BrakingAbility, r.vehData.WheelsGrip), 0f, 25f, 0f, 1f, true), 2);
- //Gravity equals to 1G when fully pointing down;
- float gravityAssist = ARS.map(r.Car.ForwardVector.Normalized.Z, -1, 1, -1, 1, true);
- //We want to decelerate this many Gs
- float targetDeceleration = ((velTarget - velCurrent) / (timeToReachTarget - 0)) / 9.8f;
- if (targetDistance == 0f) targetDeceleration = (velTarget - velCurrent);
- //We can decelerate this many Gs
- float availableDeceleration = -(((r.vehData.WheelsGrip * brakingAbility) + gravityAssist));
- //How many Gs over the car's braking ability we are allowed to go
- float Risk = DevSettingsFile.GetValue<float>("RACERS", "BaseBrakeRisk", 0.0f) + (r.mem.intention.Aggression * DevSettingsFile.GetValue<float>("RACERS", "AggroBrakeRisk", 0.0f));
- //Brake risk. There's a 0.5Gs deceleration leeway between no braking and full brake.
- float NoBrake = -0.25f + Risk;
- float FullBrake = 0.25f + Risk;
- float SpeedMod = ARS.map(targetDeceleration, availableDeceleration + NoBrake, availableDeceleration - FullBrake, -ARS.AIData.SpeedToInput, ARS.AIData.SpeedToInput, true);
- float spd = velCurrent + SpeedMod;
- return spd;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement